Ruby的rest客户端无法发送标头,当我使用如下方式从Ruby触发POST请求时,我的Java服务无法读取标头。我的服务层会抛出错误,指出Header companyID缺失。当在Postman中运行相同的http请求时,它可以正常工作。
response = RestClient::Request.new({
method: :post,
url: 'https://example.com/submitForm',
headers:{content_type: 'application/x-www-form-urlencoded',
companyID:'Company1',
Authorization:'Basic HELLO1234'},
payload: { data: str_res}
}).execute do |response, request, result|
case response.code
when 400
[ :error, JSON.parse(response.to_str) ]
when 200
[ :success, JSON.parse(response.to_str) ]
puts request.headers
else
fail "Invalid response #{response.to_str} received."
end
end
这是可用的Postman代码。需要类似的Ruby Rest代码,请指导。
POST /submitForm HTTP/1.1
Host: example.com
companyID: Company1
Authorization: Basic HELLO1234
Content-Type: application/x-www-form-urlencoded
Cache-Control: no-cache
Postman-Token: 528cafa1-2b5d-13a1-f227-bfe0171a9437
data=My Own data
CompanyID
吗?你写的是companyID
(看起来可能区分大小写)。 - Taryn East