Httparty 邮寄退货 '第422章“不可处理的实体” '
我很难弄清楚这一点。这个curl命令工作正常:
curl -v -k --basic -u"username:password" -XPOST -H"X-API-VERSION:1" -H"Accept:application/json" -H"Content-Type:application/x-www-form-urlencoded" -data'jsonData={"email":"[email protected]"}' https://api.somenetwork.net/coreg/users
但是,httparty不断返回'422“无法处理的实体”'。
这是我的代码:
class CoregBase
include HTTParty
def initialize
self.class.base_uri "https://api.somenetwork.net/coreg"
self.class.basic_auth "username", "password"
self.class.headers({'X-API-VERSION' => '1',
'Accept' => 'application/json'})
end
end
class Users < CoregBase
include HTTParty
def initialize
super
end
def create_co_registration_user
self.class.headers({ 'X-API-VERSION' => '1',
'Accept' => 'application/json',
'Content-Type' => "application/x-www-form-urlencoded"})
options = {
:body => {"email" => "[email protected]"}}
self.class.post('/users', options)
end
end
coreg_user = Users.new
result = coreg_user.create_co_registration_user
pp result
I'm having a lot of trouble figuring this out. This curl command works fine:
curl -v -k --basic -u"username:password" -XPOST -H"X-API-VERSION:1" -H"Accept:application/json" -H"Content-Type:application/x-www-form-urlencoded" -data'jsonData={"email":"[email protected]"}' https://api.somenetwork.net/coreg/users
However, httparty keeps returning '422 "Unprocessable Entity" '.
Here's my code:
class CoregBase
include HTTParty
def initialize
self.class.base_uri "https://api.somenetwork.net/coreg"
self.class.basic_auth "username", "password"
self.class.headers({'X-API-VERSION' => '1',
'Accept' => 'application/json'})
end
end
class Users < CoregBase
include HTTParty
def initialize
super
end
def create_co_registration_user
self.class.headers({ 'X-API-VERSION' => '1',
'Accept' => 'application/json',
'Content-Type' => "application/x-www-form-urlencoded"})
options = {
:body => {"email" => "[email protected]"}}
self.class.post('/users', options)
end
end
coreg_user = Users.new
result = coreg_user.create_co_registration_user
pp result
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,没关系,我明白了:
Alright nevermind, I figured it out: