curl -u "token:53555" https://url/method
如何在Net :: Http url中发送令牌,我试过
uri = URI.parse(url)
http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Get.new(uri.request_uri,{'token' => '53555'})
response = http.request(request)
但它不起作用
答案 0 :(得分:0)
尝试
uri = URI.parse(url + "?token=53555")
http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Get.new(uri.request_uri)
response = http.request(request)
答案 1 :(得分:0)
request['authorization'] = "Token token=#{token}"
像这样设置令牌。
答案 2 :(得分:0)
您需要将 basic_auth 添加到您的请求对象中。像这样:
uri = URI.parse(url)
http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Get.new(uri.request_uri)
request.basic_auth 'token', '53555'
response = http.request(request)
request.basic_auth 'token', '53555'
是添加基本身份验证代码的行。