我试图在同一台机器上的模拟器上运行的Android应用程序中调用在我的localhost中运行的java webservice,这是我的代码:
String url = "http://10.0.2.2:8080/MobileMiddleware/Registration";
HttpClient httpclient = new DefaultHttpClient();
HttpParams myParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(myParams, 30000);
HttpConnectionParams.setSoTimeout(myParams, 30000);
try {
HttpPost httppost = new HttpPost(url.toString());
httppost.setHeader("Content-type", "application/json");
StringEntity se = new StringEntity(request);
se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE,
"application/json"));
httppost.setEntity(se);
HttpResponse response = httpclient.execute(httppost);
Result = EntityUtils
.toString(response.getEntity());
Log.d(" return Result>>", Result);
}
catch (ClientProtocolException e) {}
catch (IOException e) { }
return null;
}
此代码返回错误消息Connection timeout, the gateway could not receive a timely response from the website
请帮忙