0

我正在使用 httparty gem 向 intuit(商家帐户)发送发布请求。

这是我的代码:

header = {"Content-Type" => "application/xml", 
          "content-length" => request.length 
         };

options = { :body => request,:options=>{ :headers => header} }
data = HTTParty.post(url,options) 

现在事件虽然我发送内容类型为application/xml响应错误是:

 #<HTTParty::Response:0x44278 parsed_response="Invalid content type: application/x-www-form-urlencoded.\n", @response=#<Net::HTTPBadRequest 400 Bad Request readbody=true>, @headers={"date"=>["Fri, 16 Aug 2013 15:49:50 GMT"], "server"=>["Apache"], "content-length"=>["57"], "connection"=>["close"], "content-type"=>["text/plain"]} 

我不知道我做错了什么。任何想法?

这是 data.request.inspect 的输出:

#<HTTParty::Request:0x0000000440be98 @http_method=Net::HTTP::Post, @path=#<URI::HTTPS:0x00000bba0 URL:https://merchantaccount.ptc.quickbooks.com/j/AppGateway>, @options={:limit=>5, :default_params=>{}, :follow_redirects=>true, :parser=>HTTParty::Parser, :connection_adapter=>HTTParty::ConnectionAdapter, :body=>"<?xml version=\"1.0\" ?>\n<?qbmsxml version=\"2.0\"?>\n<QBMSXML>\n<SignonMsgsRq>\n<SignonAppCertRq>\n<ClientDateTime>\#{today}</ClientDateTime>\n<ApplicationLogin>\#{APPLICATION_LOGIN} </ApplicationLogin>\n<ConnectionTicket><\#{CONNECTION_TICKET}</ConnectionTicket>\n<Language>English</Language>\n<AppID>\#{APPLICATION_ID }</AppID>\n<AppVer>1</AppVer>\n</SignonAppCertRq>\n</SignonMsgsRq>\n</QBMSXML>", :options=>{:headers=>{"Content-Type"=>"application/xml", "standalone"=>"yes", "encoding"=>"UTF-8", "content-length"=>379}}}, @last_uri=#<URI::HTTPS:0x0000000440afe8 URL:https://merchantaccount.ptc.quickbooks.com/j/AppGateway>, @raw_request=#<Net::HTTP::Post POST>, @last_response=#<Net::HTTPBadRequest 400 Bad Request readbody=true>>
4

1 回答 1

0

那应该是:

data = HTTParty.post(url, :body => request, :headers => {"Content-Type" => "application/xml"}) 

不用担心内容长度,这是 HTTParty 的工作。

于 2013-08-17T00:34:56.903 回答