Question

J'ai fait un POST sur un site en utilisant Httparty avec le code suivant :

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

Comment puis-je vérifier quel était le code de réponse pour cette soumission ?

Était-ce utile?

La solution

La valeur de retour de la méthode post est un HTTParty::Response objet, qui a une méthode de code.Attribuez votre réponse à une variable et utilisez-la pour consulter le code d'état http :

response = HTTParty.post("http://example.com", :body => application_hash.to_json, :headers => {'Content-Type' => 'application/json'})
response.code
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top