I have an app making an https post on one thread while performing a
file download on another thread.  For some odd reason, I am getting a
ClientProtocolException saying that "The server failed to respond with
a valid HTTP response".  The error goes away if everything is run on a
separate thread.

Oddly if I run the two server requests in serial, the error goes
away.  It seems there's a bug that happens when two requests are made
at the same time.

Important note:  The post occurs to a different server than the
download so the servers themselves should not be causing the problem.

The code is simple.  Here's the file download code:

HttpGet httpGet = new HttpGet(url);
HttpClient client = new DefaultHttpClient();
HttpParams params = client.getParams();
HttpConnectionParams.setConnectionTimeout(params, 15000);
HttpResponse httpResponse = client.execute(httpGet);
HttpEntity responseEntity = httpResponse.getEntity();
byte[] data = EntityUtils.toByteArray(responseEntity);

The post code's the same except for these additional lines:

HttpPut httpPut = new HttpPut(url);
httpPut.addHeader("Content-Type", "text/xml");
httpPut.setEntity(new StringEntity(postData, "UTF-8"));
BasicHttpParams parameters = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(parameters, 15000);
HttpClient client = new DefaultHttpClient();
HttpResponse httpResponse = client.execute(httpPut);
HttpEntity responseEntity = httpResponse.getEntity();
metaData = EntityUtils.toString(responseEntity);

Thanks,
Anthony

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to