HTTParty parsed_response 返回字符串而不是哈希值
如果您收到响应代码 200,HTTParty 的 parsed_response
方法将返回一个哈希值,否则无论网络服务器是否返回 XML 响应,它都会返回一个字符串。
HTTParty.get(post_url).parsed_response.class # Depends on response code
即使在 403 上,亚马逊也会提供 XML(解释出了什么问题)。
我是否遗漏了什么?
HTTParty's parsed_response
method returns a Hash if you get a response code 200 but otherwise it will return a String regardless if the webserver returns a XML response.
HTTParty.get(post_url).parsed_response.class # Depends on response code
Amazon will provide XML (explaining what went wrong) even on a 403.
Am I missing something?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
HTTParty 根据 HTTP 响应的
Content-Type
标头来解析其#parsed_response
。验证该 HTTP 标头的值是什么。就您而言,您希望它是application/xml
。HTTParty parses its
#parsed_response
based on what the HTTP response'sContent-Type
header is. Verify what the value is for that HTTP header. In your case, you'd want it to beapplication/xml
.如果今天仍然有人遇到此问题,
get
可以采用格式参数,这可以帮助您确保您的HTTParty::Response
对象是哈希:In case anyone is still encountering this issue today,
get
can take a format parameter, which can help you ensure yourHTTParty::Response
object is a Hash: