2011-03-04 277 views
0

我很困难搞清楚这一点。这个卷曲命令工作正常:Http协议帖子返回'422'不可处理的实体''

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 

回答

-1

好吧没关系,我理解了它:

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" => "[email protected]"}.to_json 

    options = {:body => "jsonData=#{j_data}"} 

    self.class.post('/users', options) 
end 
+1

请接受你自己的答案,因此下车的“悬而未决”名单。谢谢! – awendt 2011-09-01 09:18:28