views:

78

answers:

3

Hi,

I am trying to post from android to GAE, I am getting unknown host exception. Here is my code,

HttpClient httpclient = new DefaultHttpClient();  
    HttpPost httppost = new HttpPost("http://silver-kites.appspot.com");  

    try {  
        // Add your data 
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);  
        nameValuePairs.add(new BasicNameValuePair("abc", "123"));  
        nameValuePairs.add(new BasicNameValuePair("xyz", "456"));  
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));  

        // Execute HTTP Post Request  
        HttpResponse response = httpclient.execute(httppost);
        HttpEntity entity = response.getEntity();
        if(entity != null){
          InputStream inputStream = entity.getContent();
          ResponseText.setText(convertStreamToString(inputStream));
        }
    } catch (ClientProtocolException e) {
        ResponseText.setText(e.getMessage()); 
    } catch (IOException e) {
        ResponseText.setText(e.getMessage());
    }

When I am trying to connect to localhost:8888 am getting connection refused. I donno how to go pass thru this. Help me.

A: 

Try with the following (name,value) pair

nameValuePairs.add(new BasicNameValuePair("name", "123"));  
nameValuePairs.add(new BasicNameValuePair("seconds", "456"));

Now you won't get invalid parameters exception, but the response for this POST is "Sever Error" , you can check with GAE about this error.

Suresh
A: 

I tried that too, still getting Unknown Host exception in android. Do I need to do any setting for accessing HTTP? or in emulators the http wont work?

I set the <uses-permission android:name="android.permission.INTERNET"></uses-permission> in android manifest xml. Still no hopes.

Any helps? I checked in GAE and my request doesn't reach there.

Here is my code,

HttpClient httpclient = new DefaultHttpClient();  
    HttpPost httppost = new HttpPost("http://silver-kites.appspot.com/silverscores");  

    try {  

        nameValuePairs.add(new BasicNameValuePair("name", "JP"));
        nameValuePairs.add(new BasicNameValuePair("seconds", "123"));

        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));  

        // Execute HTTP Post Request  
        HttpResponse response = httpclient.execute(httppost);
        HttpEntity entity = response.getEntity();
        if(entity != null){
          InputStream inputStream = entity.getContent();
          ResponseText.setText(convertStreamToString(inputStream));
        }
    } catch (ClientProtocolException e) {
        ResponseText.setText(e.getMessage()); 
    } catch (IOException e) {
        ResponseText.setText(e.getMessage());
    }
Jai
Any help here pls.
Jai
A: 

I was doing everything fine. Only one problem was emulator was running in airplane mode, so it is not using internet connection. So I was getting unknown host exception. Now it is working fine. Thanks for your support.

Jai