作者热门文章
- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
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/
我是一名优秀的程序员,十分优秀!