Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to find response code after httparty form POST

I have made a POST to a site using Httparty with the following code:

HTTParty.post("http://example.com", :body => application_hash.to_json, :headers => {'Content-Type' => 'application/json'})

How can I check what the response code was for this submission?

like image 900
dan-mi-sun Avatar asked Jul 31 '14 16:07

dan-mi-sun


1 Answers

The return value of the post method is a HTTParty::Response object, which has a code method. Assign your response to a variable and use that to take a look at the http status code:

response = HTTParty.post("http://example.com", :body => application_hash.to_json, :headers => {'Content-Type' => 'application/json'})
response.code
like image 51
Dan Garland Avatar answered Sep 23 '22 08:09

Dan Garland