comment trouver le code de réponse après le formulaire httparty POST
-
23-12-2019 - |
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 ?
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