Skip to content

Instantly share code, notes, and snippets.

@romelemperado
Created December 10, 2012 19:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save romelemperado/26af7af09b509c0e8c2a to your computer and use it in GitHub Desktop.
Save romelemperado/26af7af09b509c0e8c2a to your computer and use it in GitHub Desktop.
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();
}
@romelemperado
Copy link
Author

REsult:

response: HTTP/1.1 400 Bad Request
Json: {"description":"test","service_key":"c2181140ee3f012ea4b912313d009e57","event_type":"trigger"}
Status code: 400

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