Thursday, April 19, 2012

Creating HTTP Connection and seinding data to server in android

//this is JSON String to put your information inside it
String postData = "{\"request\":{\"type\":\"locationinfo\"},\"userinfo\":{\"latitude\":\""+latitude+"\",\"longitude\":\""+longitude+"\",\"deviceid\":\""+deviceid+"\"}}";


HttpClient httpClient = new DefaultHttpClient();
// Post method to send data to server
HttpPost post = new HttpPost();


post.setURI(new URI("http://myserver.com/myphppage.php"));

// set your post data inside post method    
post.setEntity(new StringEntity(postData));

// execute post request here 
HttpResponse response = httpClient.execute(post);



No comments:

Post a Comment