gpt4 book ai didi

ruby-on-rails - 法拉第授权 header

转载 作者:行者123 更新时间:2023-12-03 20:34:53 27 4
gpt4 key购买 nike

我正在尝试向 Spingo 提出请求API。我已经使用 Curl 提出了成功的请求,但我正在尝试使用 Faraday gem。

成功的 curl 请求如下所示:

curl -v --url "calendarapi.spingo.com/v1/events?sections=42336"  --header 'Authorization: SpingoAPI token="my-api-key"'

最初我尝试使用默认适配器 net-http .然后我切换到 Typheous适配器因为 net-http正在大写我的 SpingoAPI授权 header 中的方案。这使它读取了 Spingoapi。现在我的请求如下所示:
  def make_request
conn = Faraday.new(base_url) do |f|
f.params['sections'] = '42336'
f.adapter :typhoeus
f.use Faraday::Response::Logger
end
conn.authorization(:SpingoAPI, token: api_key)
conn.get
end

切换到 Typheous允许某些东西返回(我没有从 net-http 得到任何东西)所以我的回复看起来像这样。
ETHON: performed EASY effective_url=url
sections=42336 response_code=200 return_code=ok total_time=0.844381
I, [2015-08-05T11:16:06.575611 #22692] INFO -- : get http://www.calendarapi.spingo.com/v1/events?sections=42336
D, [2015-08-05T11:16:06.575842 #22692] DEBUG -- request: User-Agent: "Faraday v0.9.1"

Authorization: "SpingoAPI token=\"my-token\""
I, [2015-08-05T11:16:06.576081 #22692] INFO -- Status: 200
D, [2015-08-05T11:16:06.576230 #22692] DEBUG -- response: Content-Type: "text/html; charset=utf-8"
Date: "Wed, 05 Aug 2015 17:16:03 GMT"
Server: "nginx/1.2.9"
Set-Cookie: "VisitorID=GsPJ8NLBiP; expires=Tue, 03-Nov-2015 17:16:03 GMT"
X-Powered-By: "PHP/5.3.10-1ubuntu3.11"
Content-Length: "152"
Connection: "keep-alive"

这使我相信我没有被授权,但是我对如何以不同的方式传递授权一无所知。

任何帮助将不胜感激。

最佳答案

试试这个 :

# set variables
base_url = "calendarapi.spingo.com"
url = "/v1/events"
token = "SpingoAPI token='my-api-key'"
params = {:sections => 42336}


# init connection object
connection = Faraday.new(:url => base_url) do |c|
c.use Faraday::Request::UrlEncoded
c.use Faraday::Response::Logger
c.use Faraday::Adapter::NetHttp
end

# send request
response = connection.get url, params do |request|
request.headers["Authorization"] = token
end

关于ruby-on-rails - 法拉第授权 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31839319/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com