I am using this code for POSTing JSON objeect to the URL groovy:
def http = new HTTPBuilder( 'myURL' ) // perform a POST request, expecting JSON response data http.request( POST, JSON ) { uri.path = myPath uri.query = [ service_key:'1.0', event_type: 'trigger' ] headers.'Content-Type' = 'application/json' // response handler for a success response code: response.success = { resp, json -> println resp.status // parse the JSON response object: json.responseData.results.each { ret = json.getText() println 'Response data: -----' println ret println '--------------------' } } // handler for any failure status code: response.failure = { resp -> println "Unexpected error: ${resp.status} : ${resp.statusLine.reasonPhrase}" } } Ajax Code that works:(EDITED) $.ajax({ url:'https://events.pagerduty.com/generic/2010-04-15/create_event.json', type: 'POST', contentType: 'application/json', data: JSON.stringify({ service_key: "1379ca7018e94343bf5fa5add9fa42eb", incident_key: "srv01/HTTP", event_type: "trigger", description: "TEst Test" }), dataType:'json' }); alert('Message Sent'); Everytime I get Unexpected error:400:Bad Request, Same thing if I do it with $.ajax() it works. I get HTTP:200 OK on the response.What is going wrong here?
Thank You.
http.request( POST, JSON )or is it already an appropriate format?