Sending a post request to localhost

I need to send an HTTP request from my Android device to a web server that is running on my localhost: 8080 and hosted by Google engine.

current code:

    try {

                HttpPost httppost = new HttpPost("");
                httppost.setHeader("Content-type", "application/json");
                ResponseHandler <String> responseHandler = new BasicResponseHandler();
                StringEntity se = new StringEntity(object.toString()); 
                System.out.println("Request Sent");
                String response = httpclient.execute(httppost, responseHandler);

                String temp = EntityUtils.toString(response.getEntity());

            } catch (ClientProtocolException e) {}
            catch (IOException e) {


I also tried to install:

    HttpPost httppost = new HttpPost("");


In all cases, the answer is zero, and the software force is closed. Am I sending the request correctly? can anyone guide me here?



source to share

2 answers

"Send request to localhost" means to send it to the local computer. In your case, this will be an Android device. You want to send a request to your desktop computer, which is the remote host. The problem is that appengine dev_sever by default only binds to the local address, so it cannot be retrieved remotely (i.e. from your Android device). You need to pass a parameter --address

to make it available externally. Check the IP address of the computer and pass it as an address. Something like:

dev_appserver.cmd --address=


Details here:



The response from the httpclient.execute method should be returned in a large HttpResponse variable , so changing "String" to "HttpResponse" will be fine.

HttpResponse response = (HttpResponse) httpclient.execute(httppost,responseHandler);




All Articles