最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

ruby on rails - RestClient changes x-api-key to X-Api-Key, causing 403 response - Stack Overflow

programmeradmin2浏览0评论

I'm trying to make an HTTP request using RestClient in Rails, but I'm encountering an issue with the headers. Here is the code I'm using:

headers = {
 'Content-Type' => 'application/json',
 'Authorization' => "Bearer 111",
 'x-api-key' => "12354",
 'Accept' => 'application/json;odata.metadata=minimal;odata.streaming=true'
}

params = {
 method: method,
 url: "#{@url}/#{path}",
 headers: headers
}

request = RestClient::Request.new params
response = request.execute

if response.body.present?
  JSON.parse(response.body)
else
  {}
end

The issue is that when I make the request, the x-api-key header is automatically transformed into X-Api-Key. As a result, I receive a 403 response. The request works fine from Postman or cURL because the header key is not changed there.

Is there any way to prevent RestClient from modifying the header name and send it exactly as I write it?

发布评论

评论列表(0)

  1. 暂无评论