I’m trying to perform webservice calls in android (2.3.4) using the following code snippet. My problem occurs on conn.getOutputStream, as this method seems to be taking a full 20 seconds to return. Any thoughts?
URL uri = new URL(serviceURI + "/remoteMethod");
HttpURLConnection conn = (HttpURLConnection) uri.openConnection();
conn.setDoOutput(true);
conn.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
Log.d(TAG, "opening output stream");
OutputStreamWriter writer = new OutputStreamWriter(
conn.getOutputStream());
Log.d(TAG, "output stream opened");
String body = getRequestBody();
writer.write(body);
writer.flush();
writer.close();
int responseCode= conn.getResponseCode();
It would appear that this was probably a network problem, and that jarnbjo was actually correct in his suggestion in the comments that the connection was just taking too long. I moved the server and device to another network (webservice is not public), and the problem cleared up.