0

I'm sending a post request to intuit(merchant account) using httparty gem.

Here's my code:

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

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

Now event though I'm sending content-type as application/xml The response error is:

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

I have no Idea what I'm doing wrong. Any Idea?

Here's the output for 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>>
6
  • can you inspect request and provide its contents?
    – Iuri G.
    Aug 16, 2013 at 16:03
  • THanks. can you change :body => request to :body => request.body. I think passing whole request object is confusing HTTParty and makes it override the content-type.
    – Iuri G.
    Aug 16, 2013 at 16:09
  • I'm getting undefined method `body' for #<String:0x00000003f3eaf0> Aug 16, 2013 at 16:12
  • make sure you do request.body and not request.inspect.body. according to your post, I thought request object was HTTParty object and not string.
    – Iuri G.
    Aug 16, 2013 at 16:17
  • Ah request is just a simple variable name which contains xml data in string format. Aug 16, 2013 at 16:28

1 Answer 1

1

That should probably be:

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

Don't worry about content-length, that's HTTParty's job.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.