gpt4 book ai didi

ruby - 如何在 ruby​​ 中保留自定义 header 大小写

转载 作者:数据小太阳 更新时间:2023-10-29 08:58:25 27 4
gpt4 key购买 nike

HTTP 规范说明 header 不区分大小写,我们需要调用具有区分大小写 header 的服务。

下面是我的代码

require 'uri'
require 'net/http'
require 'openssl'

url = URI("Service URL")

http = Net::HTTP::Proxy('127.0.0.1', '8888').new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE

request = Net::HTTP::Post.new(url)
request["content-type"] = 'text/xml'
request["charset"] = 'utf-8'
request["accept"] = 'text/xml'
request["host"] = 'abc.com'
request["HMACSignature"] = 'dsfsdfsdf'

response = http.request(request)
puts response.read_body

自定义 header 作为 Hmacversion 接收。

我也试过this但它不起作用。

有什么解决方法吗

最佳答案

如果可能的话,我会尝试更改服务器,这违反了 HTTP 标准,将请求 header 键视为区分大小写 - "Field names are case-insensitive" .该错误会扰乱浏览器、缓存等。

如果你不能修复它,我可能会尝试 another HTTP client library保留大小写,而不是 Net::HTTP。只要确保该库不在幕后使用 Net::HTTP 即可。例如,您可以试试 Excon(我不确定它是否保留大小写,但它有很多低级控制)。

关于ruby - 如何在 ruby​​ 中保留自定义 header 大小写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42815249/

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