将curl api调用转换为httparty

时间:2017-01-29 03:53:11

标签: ruby-on-rails ruby curl httparty

我对Httparty很新,我想通过httparty进行用户身份验证。 curl中的命令有效。

curl --data "username=USERNAME&password=PASSWORD&token=132321212" 'https://hekki.isks.com/api/userauth'

我无法将其转换为httparty。到目前为止,我有这个。

response = HTTParty.post("https://hekki.isks.com/api/userauth", 
      :username => "hello",
      :password => "no",
      :token => 132321212,
      :headers => { 'Content-Type' => 'application/json' } )

1 个答案:

答案 0 :(得分:2)

我认为应该是:

response = HTTParty.post("https://hekki.isks.com/api/userauth",
                         :body=> { 
                                    :username => "hello",
                                    :password => "no",
                                    :token => 132321212 
                                  } )