【问题标题】:Converting curl api call to httparty将 curl api 调用转换为 httparty
【发布时间】:2017-01-29 03:53:11
【问题描述】:

我对 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' } )

【问题讨论】:

  • 当您的示例未发布 json 时,为什么要使用 json 内容类型?

标签: ruby-on-rails ruby curl httparty


【解决方案1】:

我认为应该是:

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

【讨论】:

    猜你喜欢
    • 2016-06-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-29
    • 2017-12-03
    • 1970-01-01
    • 2013-03-19
    • 2017-01-04
    相关资源
    最近更新 更多