【问题标题】:I want to request below things with ruby unirest but I can't do that我想用 ruby​​ unirest 请求下面的东西,但我不能这样做
【发布时间】:2017-11-04 17:19:42
【问题描述】:

这是请求

 POST /oauth/token HTTP/1.1
 Host: api.quizlet.com
 Authorization: Basic N0pIMzhUMjd6TTpOM3JYd3l2TU5OWlNGQWNBd0ozZ3lH
 Content-Type: application/x-www-form-urlencoded; charset=UTF-8
 grant_type=authorization_code&code=GENERATED_CODE

这是回复

{
    "access_token": "46a54395f3d1108feca56c7f6ca8dd3d",
    "token_type": "bearer",
    "expires_in": 3600,
    "scope": "read",
    "user_id": "ryu_nishida"
}

这是我的代码

 Unirest.post "http://api.quizlet.com/oauth/token", 
 headers:{ Authorization: "Basic 
 N0pIMzhUMjd6TTpOM3JYd3l2TU5OWlNGQWNBd0ozZ3lH"}, 
 grant_type=authorization_code&code=GENERATED_CODE

我的代码没有响应,但不存在任何错误。

【问题讨论】:

    标签: ruby rubygems unirest


    【解决方案1】:

    您需要将响应对象保存在一个变量中,

    response = Unirest.post("http://api.quizlet.com/oauth/token",
                 auth:{:user=>"username", :password=>"password"})
    

    那么你就有了获取细节的方法

    response.code # Status code
    response.headers # Response headers
    response.body # Parsed body
    response.raw_body # Unparsed body
    

    阅读docs

    【讨论】:

    • 我阅读了文档,但我不明白应该在哪里写 grant_type。
    • 在 WordsController#new /Users/nishidaryu/RubymineProjects/share- tan/app/controllers/words_controller.rb:190 中发生错误 SyntaxError:语法错误,意外 ')',期待 =>
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-12
    • 1970-01-01
    • 2021-02-02
    • 1970-01-01
    • 1970-01-01
    • 2023-03-06
    相关资源
    最近更新 更多