简体   繁体   中英

Rails: Parsing HTTParty

I've read other answers on this topic, such as:

Parsing HTTParty response

HTTParty parsing JSON in Rails

However, I still can't figure out how to parse a response I'm receiving.

response.parsed_response = HTTParty.get(url, query: params) returns:

=> #<HTTParty::Response:0x89435d0 parsed_response="http://foo.com", @response=#<Net::HTTPOK 200 OK readbody=true>, @headers={"cache-control"=>["no-cache", "no-store"], "date"=>["Tue, 21 Feb 2017 23:10:47 GMT"], "expires"=>["Thu, 01 Jan 1970 00:00:00 GMT"], "p3p"=>["CP=\\"ALL IND DSP COR CUR ADM TAIo PSDo OUR COM INT NAV PUR STA UNI\\""], "pragma"=>["no-cache"], "server"=>["Apache-Coyote/1.1"], "set-cookie"=>["bar.Agent.p=c1921b97d1f8a0918621c48bd32ded2b; Domain=.bar.com; Expires=Fri, 19-Feb-2027 23:10:47 GMT; Path=/"], "content-length"=>["366"], "connection"=>["Close"]}>

I need the URL that appears after parsed_response . The other answers seemed to break down hashes that appear after parsed_response, but I'm just looking for the url that appears after parsed_response (and it only appears there in the response).

I tried: puts response which returns the entire response above.

puts response.parsed_response which returns:

http://foo.com
=> nil

This usually works for me

response = HTTParty.get(url, options)
puts response.body

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM