簡體   English   中英

如何在我的get`request`中添加`headers`。

[英]How to add `headers` to my get `request`.

如何將headers添加到我的get request

it "can find an account" do 
    get "/accounts/#{@acc.id}/", headers # like the token or whatever your api needs
end

下面是我傳遞令牌的controller方法,現在該如何將其append到我的get request

Account.find(id: @acc.id, authorization: @auth_token);

使用request.env設置標題

it "can find an account" do 
   request.env['AUTH_TOKEN'] = "token"
   get "/accounts/#{@acc.id}/"
end

您可以將標頭作為第三個參數發送,以get

get "/accounts/#{@acc.id}/", nil, {'AUTH_TOKEN' => 'token'}.

請參閱文檔以獲取更多信息。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM