Home Https request wth user auth rails
Reply: 3

Https request wth user auth rails

petspanda D
1#
petspanda D Published in 2018-01-12 12:02:22Z
curl -u "token:53555" https://url/method

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

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

Salil
2#
Salil Reply to 2018-01-12 12:07:15Z

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)
Daniel
3#
Daniel Reply to 2018-01-12 12:14:02Z

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

Jonathan Duarte
4#
Jonathan Duarte Reply to 2018-01-12 14:31:01Z

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

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.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.304781 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO