Https请求用户auth rails

时间:2022-01-28 16:54:59
curl -u "token:53555" https://url/method

how to send token in Net::Http url, I tried as

如何在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)

But its not working

但它不起作用

3 个解决方案

#1


0  

Try

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)

#2


0  

request['authorization'] = "Token token=#{token}" Set token like this.

request ['authorization'] =“令牌令牌=#{token}”像这样设置令牌。

#3


0  

You need to add basic_auth to your request object. Like so:

您需要将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)

The request.basic_auth 'token', '53555' is the line that adds the basic authentication code.

request.basic_auth'token','53555'是添加基本身份验证代码的行。

#1


0  

Try

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)

#2


0  

request['authorization'] = "Token token=#{token}" Set token like this.

request ['authorization'] =“令牌令牌=#{token}”像这样设置令牌。

#3


0  

You need to add basic_auth to your request object. Like so:

您需要将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)

The request.basic_auth 'token', '53555' is the line that adds the basic authentication code.

request.basic_auth'token','53555'是添加基本身份验证代码的行。