Ruby相当于curl与-H(标题)开关

时间:2015-07-11 05:34:31

标签: ruby-on-rails ruby curl

我想做这个curl请求的功能,但是在Ruby中:

w-Token

我正在努力解决的问题是:如何在常规HTTPS请求结束时添加 compileOptions { sourceCompatibility JavaVersion.VERSION_1_7 targetCompatibility JavaVersion.VERSION_1_7 }

2 个答案:

答案 0 :(得分:2)

-H表示HTTP标头。您可以使用HTTPClient

传递

安装httpclient gem

gem install httpclient

然后使用下面的代码示例获取URL

require 'httpclient'

uri = "https://api.wheniwork.com/2/shifts/"
query = "location_id=1&start=2014-03-05"
clnt = HTTPClient.new
extheader = { 'W-Token' => 'ilovemyboss' }
clnt.get_content(uri, query, extheader)

答案 1 :(得分:1)

以下是使用标准库net / http:

完成此操作的示例

require 'net/http'
url = '...'
uri = URI(url)
http = Net::HTTP.new(uri.host)
request = Net::HTTP::Get.new(uri.path)
request['authorization'] = %{Token token="#{password}", userID="#{user_id}"}
res = http.request(request)