0

私はこれを理解するのに非常に苦労しています。この 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
4

1 に答える 1

-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" => "dms_testABCC@test.com"}.to_json

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

  self.class.post('/users', options)
end
于 2011-03-04T21:02:33.240 に答える