Ruby - >获取RestClient :: UnprocessableEntity:422不可处理的实体

[英]Ruby -> getting RestClient::UnprocessableEntity: 422 Unprocessable Entity


I have something as simple as this, and I get a error 422

我有一些简单的东西,我得到一个错误422

irb(main):024:0> RestClient.post 'http://dev.myServer.es/api/register', '{"first_name": "John"}', :content_type=>'application/json'

RestClient::UnprocessableEntity: 422 Unprocessable Entity

However, when I run the same with Curl works OK:

但是,当我运行相同的Curl工作正常时:

curl --location "http://dev.myServer.es/api/register" -H 'Content-Type: application/json' -d '{"first_name": "John"}'


{"status": "OK"}

I am quite new to Ruby... but I don't know what I am missing?

我对Ruby很陌生......但我不知道我错过了什么?

1 个解决方案

#1


1  

There's an example in the docs - https://github.com/rest-client/rest-client#usage-raw-url - which shows:

文档中有一个例子 - https://github.com/rest-client/rest-client#usage-raw-url - 显示:

RestClient.post "http://example.com/resource", {'x' => 1}.to_json, {content_type: :json, accept: :json}

Try replacing:

尝试更换:

:content_type=>'application/json'

in your call, with:

在你的电话中,有:

content_type: :json
智能推荐

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.itdaan.com/blog/2017/11/12/6f89b74c88912a5d0c3398279d966473.html



 
© 2014-2019 ITdaan.com 粤ICP备14056181号  

赞助商广告