0

我正在尝试使用Orange SMS API ,我在这里阅读了如何使用它。

我想从 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=#, @headers={"date"=>["Wed, 21 Sep 2016 13:35:37 GMT"], "cache-control "=>["无缓存"], "内容类型"=>["文本/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=#, @headers={"date"=>["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 中做到这一点。

4

0 回答 0