Skip to content

Instantly share code, notes, and snippets.

@guilleiguaran
Forked from Manuel-E/Connection.java
Created June 3, 2012 21:09
Show Gist options
  • Save guilleiguaran/2865051 to your computer and use it in GitHub Desktop.
Save guilleiguaran/2865051 to your computer and use it in GitHub Desktop.
public class Connection {
String URL = "http://iwarn-staging.herokuapp.com/";
String result = "";
String deviceId = "xxxxx" ;
final String tag = "Your Logcat tag: ";
public void callWebServiceForSendData(String jsonData){
HttpClient httpclient = new DefaultHttpClient();
HttpPost sender = new HttpPost(URL+"events.json");
sender.addHeader("Accept"," application/json");
sender.addHeader("Content-Type", "application/json");
//Body: {"event": {"description": null, "latitude": 70.1, "longitude": 11.0, "state": "registered", "type": "simple"}}
sender.addHeader("deviceId", deviceId);
sender.setEntity(new StringEntity(jsonData));
ResponseHandler<String> handler = new BasicResponseHandler();
try {
//result = httpclient.execute(sender, handler);
HttpResponse responset = httpclient.execute(sender);
} catch (ClientProtocolException e) {
e.printStackTrace();
result = e.toString();
} catch (IOException e) {
e.printStackTrace();
result = e.toString();
}
httpclient.getConnectionManager().shutdown();
Log.i(tag, result);
} // end callWebService()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment