我很难弄清楚这一点。此 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/users
但是,httparty 不断返回 '422 "Unprocessable Entity" '。
这是我的代码:
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