如何在httparty表单POST后找到响应代码

时间:2014-07-31 16:32:28

标签: post httparty http-response-codes

我使用Httparty使用以下代码对网站进行了POST:

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

如何查看此提交的响应代码?

1 个答案:

答案 0 :(得分:11)

post方法的返回值是HTTParty::Response对象,它有一个代码方法。将您的响应分配给变量并使用它来查看http状态代码:

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