如何使用 httparty 在 Ruby 中调用 XML 请求



在Ruby中调用XML请求API时,它得到XML解析器错误作为响应。

接口调用

require 'httparty'
    response = HTTParty.post("http://www.99acres.com/99api/v1/getmy99Response/test/uid/",
    :headers => {"Accept" => "application/xml", "Content-Type" =>"application/xml"},
    :body => '<?xml version="1.0"?><query>
    <user_name>test</user_name><pswd>testest</pswd><start_date>2019-03-25 12:03:00</start_date><end_date>2019-04-24 12:04:00</end_date></query>'
)

错误响应


错误-0000XML 解析 错误

如何在 ruby 中调用 XML 请求 API?.

您向 API 编写了正确的请求,但看起来他们只是没有让您访问 API,看起来您的登录凭据不正确,但您的代码没有问题!

这个来自 API 的响应!

#<HTTParty::Response:0x7ff11da769b0 parsed_response={"response"=>{"code"=>"1", "msg"=>"INVALID KEY"}}, @response=#<Net::HTTPUnauthorized 401 Unauthorized readbody=true>, @headers={"server"=>["nginx"], "content-type"=>["text/xml;charset=UTF-8"], "content-length"=>["85"], "content-security-policy-report-only"=>["block-all-mixed-content; report-uri https://track.99acres.com/csp_logging.php;"], "etag"=>[""d41d8cd98f00b204e9800998ecf8427e""], "date"=>["Wed, 24 Apr 2019 18:46:46 GMT"], "connection"=>["close"], "set-cookie"=>["99_ab=20; expires=Thu, 23-Apr-2020 18:46:46 GMT; Max-Age=31536000; path=/"]}>