gpt4 book ai didi

android - Android 模拟器中 Unresolved 主机异常

转载 作者:搜寻专家 更新时间:2023-11-01 09:13:14 24 4
gpt4 key购买 nike

我正在尝试通过传递 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;
}

我将 url 传递为: http://abcd.appspot.com/

但是当代码在 emulator 中执行时,我收到“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)

最佳答案

这可能是您的模拟器没有连接到互联网。通过启动浏览器检查您的模拟器是否能够连接到互联网,如果不能重新启动模拟器。

关于android - Android 模拟器中 Unresolved 主机异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6674312/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com