-
-
Save guilleiguaran/2865051 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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