22

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?

dan-mi-sun
  • 551
  • 2
  • 4
  • 18

1 Answers1

48

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
Dan Garland
  • 3,350
  • 1
  • 24
  • 24
  • Thanks, along with print response.code at the end of the line I was able to output the response to the command line. – dan-mi-sun Aug 01 '14 at 10:50