I am trying to POST using Rest-Client gem in Ruby, and I keep getting a return from the web service as Error 414 Unsupported Media Type, because I am setting the payload argument as ''
Example
RestClient.post 'https://username:password@remotesystem/api/v1/applications/44204093/publishUpdates','' ,:accept => 'json'
The issue is that the web service does not want or need a payload for this resource, but the RestClient feels the need to have one specified.
Anyone know how to do a post with rest client and not have to specify a payload argument?
thanks
For post I believe the method is url, payload, header
url = 'https://username:password@remotesystem/api/v1/applications/44204093/publishUpdates'
header = {'Accept' => 'application/json'}
RestClient.post url, {}, header
This is off the top of my head, but this tripped me up as well.
Gem is rest-client 1.8.0, most current stable one. I am also getting this error RestClient::UnsupportedMediaType: 415 Unsupported Media Type from /Users/Ben/.rvm/gems/ruby-2.1.5@caredox/gems/rest-client-1.8.0/lib/restclient/abstract_response.rb:74:in `return!'
For calling post and response is a JSON
RestClient.post(url,
{
:arg1 => var1
},
{:Authorization => "Bearer blahblah",
:content_type => :json,
:accept => :json
}
)
This started happening for me in ruby 2.4. Ruby 1.9 didn't have this problem, for the same version of rest-client. If no payload is specified in the call, the content-type header was being set to 'application/x-www-form-urlencoded' which caused the server to say 'No operation matching request path ...' and return '415 Unsupported Media Type'. The solution was to explicitly set content-type to nil in the call:
RestClient::Request.execute(:url => query, :ssl_version => 'TLSv1', :method => 'post', :headers => {'Content-Type' => nil})
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.