2

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)
Otra
  • 8,108
  • 3
  • 34
  • 49
vbjain
  • 547
  • 2
  • 7
  • 23

2 Answers2

2

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.

sunriser
  • 770
  • 3
  • 12
  • Yes i tried to connect with browser and all is working well. The same site is getting open in my browser of emulator. I had restarted it so many times. But when i launch my application i am getting the issue in accessing internet from my application in emulator. – vbjain Jul 13 '11 at 05:36
  • please check above i had provided the logcat with question only. – vbjain Jul 13 '11 at 12:45
0

the above URL http://abcd.appspot.com/ did not open in browser,I have checked itenter image description here,please check it once again

sunriser
  • 770
  • 3
  • 12