我使用以下代码使用Httparty向网站进行了POST请求:
HTTParty.post("http://example.com", :body => application_hash.to_json, :headers => {'Content-Type' => 'application/json'})
我该如何检查此提交的响应代码?
我使用以下代码使用Httparty向网站进行了POST请求:
HTTParty.post("http://example.com", :body => application_hash.to_json, :headers => {'Content-Type' => 'application/json'})
我该如何检查此提交的响应代码?
post方法的返回值是一个HTTParty::Response
对象,它具有一个code方法。将响应分配给一个变量,并使用它来查看HTTP状态代码:
response = HTTParty.post("http://example.com", :body => application_hash.to_json, :headers => {'Content-Type' => 'application/json'})
response.code