2

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

2 回答 2

2

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

于 2011-07-13T05:10:40.147 回答
0

上面的网址http://abcd.appspot.com/没有在浏览器中打开,我已经检查过了在此处输入图像描述,请再检查一次

于 2011-07-13T16:49:23.987 回答