k9b*_*k9b 5 ruby authentication api rest
简单的代码
require 'net/http'
url = URI.parse('get json/other data here [link]')
req = Net::HTTP::Get.new(url.to_s)
res = Net::HTTP.start(url.host, url.port) {|http|
http.request(req)
}
puts res.body
Run Code Online (Sandbox Code Playgroud)
只是想知道如何在php cURL中放置一个身份验证令牌,我就是这样做的
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer xxx')); //Bearer token for authentication
Run Code Online (Sandbox Code Playgroud)
想知道如何为Ruby做这件事.
zis*_*she 11
你可以简单地添加标题:
req = Net::HTTP::Get.new(url.to_s)
req['Authorization'] = "Bearer xxx"
Run Code Online (Sandbox Code Playgroud)
或更短:
request = Net::HTTP::Get.new(url.to_s, {'Authorization' => 'Bearer vF9dft4qmT'})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4853 次 |
| 最近记录: |