Closed ishuah closed 7 years ago
I'm also experiencing the same behavior with the same code.
I am also having this problem 😞
A bit late but the issue is that in your sample it didn't look like you were actually sending it JSON even though you set the content type.
2.2.2 :004 > Unirest.post("http://httpbin.org/post", headers:{ "Content-Type" => "application/json" }, parameters: { "a"=> "b"}.to_json ).body
=> {"args"=>{}, "data"=>"{\"a\":\"b\"}", "files"=>{}, "form"=>{}, "headers"=>{"Accept"=>"*/*; q=0.5, application/xml", "Accept-Encoding"=>"gzip", "Content-Length"=>"9", "Content-Type"=>"application/json", "Host"=>"httpbin.org", "User-Agent"=>"unirest-ruby/1.1"}, "json"=>{"a"=>"b"}, "origin"=>"174.104.207.158", "url"=>"http://httpbin.org/post"}
2.2.2 :005 > Unirest.post("http://httpbin.org/post", headers:{ "Content-Type" => "application/json" }, parameters: { "a"=> "b"} ).body
=> {"args"=>{}, "data"=>"", "files"=>{}, "form"=>{"a"=>"b"}, "headers"=>{"Accept"=>"*/*; q=0.5, application/xml", "Accept-Encoding"=>"gzip", "Content-Length"=>"3", "Content-Type"=>"application/x-www-form-urlencoded", "Host"=>"httpbin.org", "User-Agent"=>"unirest-ruby/1.1"}, "json"=>nil, "origin"=>"174.104.207.158", "url"=>"http://httpbin.org/post"}
cc @nikz
@iCreateJB thanks for responding.
I know it's almost a year gone but I like to see things resolved.
I've just tested with version 1.0.8
and it looks good.
Closing this issue.
I'm trying to post JSON data but the host is interpreting the request as XML. I tested with httpbin.org, results below.
The post request:
Unirest.post("http://httpbin.org/post", headers:{ "Content-Type" => "application/json" }, parameters: { "a"=> "b"} )
The response:
The
Headers
key (uppercase h) contains the correct header values, while theheaders
key (lowercase h) contains different header values. Theheaders
key is the one that's being accepted.