Reputation: 557
I'm trying to call a servlet deployed on App Engine by passing JSON parameters. Below is the code:
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;
}
I am passing the url as: http://abcd.appspot.com/
But when code is getting executed in emulator i am getting "java.net.UnknownHostException: Host is unresolved" error. But while executing the same code in Android 2.2.1 device all things are working fine. But not able to execute the code in any of the emulator i tried with all versions.
Stacktrace:
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)
Upvotes: 2
Views: 4089
Reputation: 780
the above URL http://abcd.appspot.com/ did not open in browser,I have checked it,please check it once again
Upvotes: 0
Reputation: 780
It may be your emulator not connected to internet.Check whether your emulator able to connect to internet or not by launching browser,if not restart emulator.
Upvotes: 2