0

I'm connecting my Application to a REST type webservice. I'm using the apache http library, the request is a standard post request, ran in a background thread.

Now my problem is that if I'm using

http://myserver.com/api/command

it works and I get the proper response, but the same url with https:

https://myserver.com/api/command

I get an empty response. The http header is even 200 OK.

BOTH of these work on 2.0.3 but not on 4.0.3. On 4.0.3 the API seems to work only if I use plain http, with https I get empty responses.

This is the code:

@Override
protected HttpResponse doInBackground(String... params) {
    String link = params[0];
    HttpClient client = createHttpClient();
    try {
        HashMap<String, ContentBody> files = ApiManager.getFiles();
        MultipartEntity mpEntity = new MultipartEntity();
        if(files != null)  {
            for(String i : files.keySet()) {
                ContentBody k = files.get(i);
                mpEntity.addPart(i, k);
            }
        }
        if(this.callParameters != null) {
            for(NameValuePair i : this.callParameters) {
                StringBody sb = new StringBody((String)i.getValue(),"text/plain",Charset.forName("UTF-8"));
                mpEntity.addPart(i.getName(), sb);
            }
        }
        httppost.setEntity(mpEntity);
        // Execute HTTP Post Request
        Log.d("ApiTask","Executing request: "+httppost.getRequestLine());
        HttpResponse response = null;
        response = client.execute(httppost);
        client.getConnectionManager().shutdown();
        return response;
    } 
    catch(UnknownHostException e) {
        exception = e;
        return null;
    }
    catch (IOException e) {
        exception = e;
        return null;
    }
    catch(Exception e) {
        return null;
    }
}

@Override
protected void onPostExecute(HttpResponse result) {
    System.out.println("STATUS:"+result.getStatusLine());
    try {
        StringBuilder responseText = this.inputStreamToString(result.getEntity().getContent());
        System.out.println("RESPONSE:"+responseText);
    }
    catch(Exception e) {
        System.out.println("Error");
    }
}

private HttpClient createHttpClient() {
    HttpParams params = new BasicHttpParams();
    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(params, HTTP.DEFAULT_CONTENT_CHARSET);
    HttpProtocolParams.setUseExpectContinue(params, true);
    HttpConnectionParams.setConnectionTimeout(params, 10000);
    HttpConnectionParams.setSoTimeout(params, 10000);

    SchemeRegistry schReg = new SchemeRegistry();
    schReg.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    schReg.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
    ClientConnectionManager conMgr = new ThreadSafeClientConnManager(params, schReg);
    return new DefaultHttpClient(conMgr, params);
}

Thank you in advance

user2001951
  • 185
  • 1
  • 3
  • 14

0 Answers0