Skip to content

Instantly share code, notes, and snippets.

@gideondsouza
Created June 3, 2012 18:18
Show Gist options
  • Save gideondsouza/2864460 to your computer and use it in GitHub Desktop.
Save gideondsouza/2864460 to your computer and use it in GitHub Desktop.
Send a GET request to a server.
public void postData(String la, String lo) {
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpGet htget = new HttpGet("http://<your_app_url>/Home/Book/"+la+"/"+lo);
try {
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(htget);
String resp = response.getStatusLine().toString();
Toast.makeText(this, resp, 5000).show();
} catch (ClientProtocolException e) {
Toast.makeText(this, "Error", 5000).show();
} catch (IOException e) {
Toast.makeText(this, "Error", 5000).show();
}
}
@sulphar
Copy link

sulphar commented Dec 21, 2012

hi bro, I have a android app which have the same code above ,it find the lat long coordinates using Network location , i just want to send lat long coordinates to my working server( which already have a APP which is listening on a specific port and receive all the data coming from different trackers and translates coordinates into the address )
So when i changed this line
HttpGet htget = new HttpGet("http://<your_app_url>/Home/Book/"+la+"/"+lo);
with
HttpGet htget = new HttpGet("http://180.178.168.43:6081/"+la+"/"+lo);
It send the data to my server and i can see these information on my server

  • Get /31.2335709/74.4932121 HTTP/1.1
  • Host: 180.176.162.42:6081
  • Connection: Keep-Alive
  • User-Agent: Apache-HttpClient/Unavailable (java 1.4)

At that points everything worked but my android app get stuck after sending that data,any help ??

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment