我正在使用 Ruby Faraday gem 向 Bitstamp API 發出一些請求。
我想用一個空的正文發出這個請求(以獲取我的帳戶余額)。 post我遇到的問題是法拉第Content-type在請求執行期間在中間件中添加了一個標頭。當正文為空時, Bitstamp API 不允許包含Content-type標頭,因此出現以下錯誤:
BitstampClient::Error: Bitstamp error: 403 {"status": "error", "reason": "Content-Type header should not be present", "code": "API0020"
我怎樣才能排除Content-type標題?我在 Postman 中測驗了同樣的請求,效果很好。所以我確定這是問題所在。
uj5u.com熱心網友回復:
我的構建器如下: <Faraday::RackBuilder:0x000000401e9f2208 @adapter=Faraday::Adapter::NetHttp, @handlers=[Faraday::Request::UrlEncoded]>
是的,UrlEncoded中間件添加了Content-Type標頭。檔案:
中間件還會自動將 Content-Type 標頭設定為 application/x-www-form-urlencoded。 https://github.com/lostisland/faraday/blob/8f00640dd51da00c8ca09f29bca0a2b32c553925/docs/middleware/request/url_encoded.md
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/451375.html
上一篇:我的API呼叫適用于郵遞員,但不適用于curl,因為它無法讀取查詢引數
下一篇:AxiosPUT請求-React
