-
-
Save romelemperado/26af7af09b509c0e8c2a 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
HttpClient client = new DefaultHttpClient(); | |
HttpConnectionParams.setConnectionTimeout(client.getParams(), 10000); //Timeout Limit | |
HttpResponse response; | |
JSONObject json = new JSONObject(); | |
try{ | |
HttpPost post = new HttpPost("https://events.pagerduty.com/generic/2010-04-15/create_event.json"); | |
json.put("description","test"); | |
json.put("event_type","trigger"); | |
json.put("service_key","c21811xxxx912313xxx9e57"); | |
StringEntity se = new StringEntity( "JSON: " + json.toString()); | |
se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json")); | |
post.setEntity(se); | |
response = client.execute(post); | |
// Log.i("PD",response.getStatusLine().toString()); | |
/*Checking response */ | |
/*if(response!=null){ | |
InputStream in = response.getEntity().getContent(); //Get the data in the entity | |
*/ | |
int statusCode = response.getStatusLine().getStatusCode(); | |
SmsToEmail pdemail = new SmsToEmail(); | |
pdemail.sendToMail("\nresponse: "+response.getStatusLine().toString()+"\nJson: "+json.toString()+"\nStatus code: "+statusCode,"status code", "xxxado@gmail.com"); | |
} | |
catch(Exception e){ | |
e.printStackTrace(); | |
// createDialog("Error", "Cannot Estabilish Connection"); | |
} | |
stopSelf(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
REsult:
response: HTTP/1.1 400 Bad Request
Json: {"description":"test","service_key":"c2181140ee3f012ea4b912313d009e57","event_type":"trigger"}
Status code: 400