如何将此curl命令转换为Rails中的httparty?使用Orange SMS Api

时间:2016-09-21 13:50:55

标签: ruby-on-rails api curl httparty orange-api

我正在尝试使用Orange SMS API,我读了如何使用它here

我想在Rails应用程序中使用这个api。

我想将此curl命令转换为httparty代码。

curl -X POST \
-H "Authorization: {authorization_header}" \
-d "grant_type=client_credentials" \
https://api.orange.com/oauth/v2/token

我搜索了很多解决方案,但都失败了:(

这是最后一次尝试

HTTParty.post(
      "https://api.orange.com/oauth/v2/token",
      headers: { 
        "Content-Type" => "application/x-www-form-urlencoded", 
        "Authorization" => "Basic {authorization_header}",
        "Accept" => "application/json"
      },
      body: {
        :grant_type => "client_credentials"
      }.to_json
    )

但是我收到了这个错误:

  

504网关超时

\ n服务器没有及时响应。\ n \ n“,@ response =#,@ head = {”date“=> [“Wed,21 Sep 2016 13:35:37 GMT”],“cache-control”=> [“no-cache”],“content-type”=> [“text / html; charset = UTF-8“],”connection“=> [”close“],”transfer-encoding“=> [”chunked“]}>      

IRB(主):073:0>

我也试过这种方式

       access_token = HTTParty.post(
         "https://api.orange.com/oauth/v2/token",
         headers: { "Content-Type" => "application/x-www-form-urlencoded", "Authorization" => "Basic {authorization_header}"},
         query: { "grant_type" => "client_credentials" }
       )

但是我收到了这个错误:

  

=> #“invalid_grant”,“error_description”=>“参数grant_type无效。”},@ response =#,@ header = {“date”=> [“Wed,2016年9月21日13:14:18 GMT “],”host“=> [”ope-apigee-private“],”content-type“=> [”application / json“],”authorization“=> [”Basic cWVnaUJlR0xhcndaYzZ0R1dtS1JqUFE2d0FBOVNEWW46SFJ1SGFURUJlOHR2aHlTOA ==“], “x-forwarded-for”=> [“213.181.226.205,192.168.70.3”,“192.168.9.45”],“x-forwarded-host”=> [“api.orange.com”],“x -forwarded-server“=> [”OPOPECBALLAP04“],”content-length“=> [”86“],”connection“=> [”close“]}>

我不知道如何使用它我阅读官方的方式,它使用Curl工作,但我不能在Rails中。

0 个答案:

没有答案