Ruby Httparty post返回';422“;“不可加工实体”';
我很难弄明白这一点。此curl命令工作正常:Ruby Httparty post返回';422“;“不可加工实体”';,ruby,httparty,Ruby,Httparty,我很难弄明白这一点。此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":"tech@usamp.com"}' https://api.somenetwork.net/coreg/use
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":"tech@usamp.com"}' https://api.somenetwork.net/coreg/users
但是,HttpParty不断返回“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" => "dms_testABCC@test.com"}}
self.class.post('/users', options)
end
end
coreg_user = Users.new
result = coreg_user.create_co_registration_user
pp result
class-CoregBase
包括HTTParty
def初始化
self.class.base_uri“https://api.somenetwork.net/coreg"
self.class.basic_auth“用户名”、“密码”
self.class.headers({'X-API-VERSION'=>'1',
'接受'=>'应用程序/json'})
结束
结束
类用户'1',
'接受'=>'应用程序/json',
“内容类型”=>“应用程序/x-www-form-urlencoded”})
选项={
:body=>{“email”=>“dms”_testABCC@test.com"}}
self.class.post('/users',选项)
结束
结束
coreg_user=Users.new
结果=coreg_user.create_co_registration_user
pp结果
好吧,不管怎样,我想出来了:
def create_co_registration_user
self.class.headers({ 'X-API-VERSION' => '1',
'Accept' => 'application/json',
'Content-Type' => "application/x-www-form-urlencoded"})
j_data = {"email" => "dms_testABCC@test.com"}.to_json
options = {:body => "jsonData=#{j_data}"}
self.class.post('/users', options)
end
请接受您自己的答案,这样它就不会出现在“未回答”列表中。谢谢