【发布时间】:2021-07-05 18:24:07
【问题描述】:
我在 Curl 中使用以下请求
curl -X GET -k -H 'Content-Type: application/json' -H 'Authorization: Bearer XXXXXXX' -H 'RowId: 100' -i 'https://url.xxx/row'
以及使用 REST_CLIENT (2.1.0) 的请求:
RestClient::Request.execute(:url => "https://url.xxx/row", :method => :get, :verify_ssl => false, :headers => {:content_type => "application/json", :Authorization => "Bearer XXXXXXX", :RowId => 100})
RestClient::NotFound: 404 未找到
第一个(Curl)正在工作,但 RestClient 中的等效请求没有。
问题是 rest-client 没有传递所有标头: {:content_type => "application/json", :Authorization => "Bearer XXXXXXX", :RowId => 100}
仅使用 content_type 和 Authorization,其他在请求发送时不使用
net/http 也有类似的问题:
require 'net/http'
uri = URI('https://url.xxx/row')
https = Net::HTTP.new(uri.host, uri.port)
https.use_ssl = true
https.verify_mode = OpenSSL::SSL::VERIFY_NONE
https.ssl_version = :TLSv1
req = Net::HTTP::Get.new uri
req['content_type'] = 'application/json'
req['Authorization'] = "Bearer #{token}"
req['RowId'] = 100
res = https.request req
puts res.body
有什么建议吗? 谢谢
【问题讨论】:
-
您使用的是哪个 gem 版本的 rest-client?
-
@Mshka 2.1.0 版
标签: ruby curl rest-client net-http