Rails: 解析 HTTParty

Rails: Parsing HTTParty

我已经阅读了有关此主题的其他答案,例如:

但是,我仍然不知道如何解析我收到的响应。

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"]}>

我需要 parsed_response 之后出现的 URL。其他答案似乎分解了 parsed_response 之后出现的哈希值,但我只是在寻找 parsed_response 之后出现的 url (它只出现在响应中)。

我试过: puts response 其中 returns 上面的整个回复。

puts response.parsed_response 其中 returns:

http://foo.com
=> nil

这通常适合我

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