Domanda

Ho fatto un post su un sito usando httparty con il seguente codice:

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

Come posso controllare cosa fosse il codice di risposta per questa sottomissione?

È stato utile?

Soluzione

Il valore di ritorno del metodo Post è un oggetto HTTParty::Response, che ha un metodo di codice.Assegna la tua risposta a una variabile e usa quella da dare un'occhiata al codice di stato HTTP:

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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top