0
我正在使用httparty gem向intuit(商家帳戶)發送一個post請求。無效的內容類型:應用程序/ x-www-form-urlencoded使用httparty
這裏是我的代碼:
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>>
你能檢查請求並提供其內容嗎? –
請查看我更新的代碼 –
THanks。你可以把':body => request'改成':body => request.body'。我認爲傳遞整個請求對象會使HTTParty混淆並使其覆蓋內容類型。 –