我试图通过传递JSON参数来调用部署在App Engine上的servlet。以下是代码:
public static String doPost(String url, String jsonData)
throws ClientProtocolException, IOException {
HttpClient httpclient = new DefaultHttpClient();
HttpConnectionParams.setConnectionTimeout(httpclient.getParams(), 0); // Timeout
HttpPost request = new HttpPost(url);
StringEntity s = new StringEntity(jsonData);
s.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE,"application/json"));
HttpEntity entity = s;
request.setEntity(entity);
HttpResponse response = httpclient.execute(request);
HttpEntity resEntity = response.getEntity();
if (resEntity != null) {
// Log.i("RESPONSE", EntityUtils.toString(resEntity));
String responseData = EntityUtils.toString(resEntity).trim();
return responseData;
}
return null;
}
我将网址传递给: http://abcd.appspot.com/
但是当代码在 模拟器 中执行时,我收到“java.net.UnknownHostException:Host is unresolved”错误。但是在 Android 2.2.1设备 中执行相同的代码时,一切正常。但是我无法在所有版本的 模拟器 中执行代码。
堆栈跟踪:
W/System.err( 987): java.net.UnknownHostException: Host is unresolved: aamjantaatest.appspot.com:80
W/System.err( 987): at java.net.Socket.connect(Socket.java:1002) W/System.err( 987): at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:117)
W/System.err( 987): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:129)
W/System.err( 987): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
W/System.err( 987): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
W/System.err( 987): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:348)
W/System.err( 987): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
W/System.err( 987): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
W/System.err( 987): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
W/System.err( 987): at com.aamjantaa.android.service.Request.doPost(Request.java:62)
W/System.err( 987): at com.aamjantaa.android.intent.StoreListView$StoreListAsynTask.doInBackground(StoreListView.java:170)
W/System.err( 987): at com.aamjantaa.android.intent.StoreListView$StoreListAsynTask.doInBackground(StoreListView.java:1)
W/System.err( 987): at android.os.AsyncTask$2.call(AsyncTask.java:185)
W/System.err( 987): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:256)
W/System.err( 987): at java.util.concurrent.FutureTask.run(FutureTask.java:122)
W/System.err( 987): at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:648)
W/System.err( 987): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:673)
W/System.err( 987): at java.lang.Thread.run(Thread.java:1058)
答案 0 :(得分:3)
可能是您的模拟器未连接到互联网。如果没有重新启动模拟器,请检查您的模拟器是否能够通过启动浏览器连接到互联网。
答案 1 :(得分:0)
以上网址http://abcd.appspot.com/未在浏览器中打开,我已对其进行了检查,请再次查看
答案 2 :(得分:0)
Unresolved Host Exception Android
检查此链接似乎是类似的问题,这对我有用
答案 3 :(得分:0)