我有其余的客户端gem,我正在定义这样的请求:
url = 'http://someurl'
request = {"data" => data}.to_json
response = RestClient.post(url,request,:content_type => :json, :accept => :json)
Run Code Online (Sandbox Code Playgroud)
但是我需要将HTTP标头设置为某种东西.例如API密钥.这可以在curl中完成:
curl -XHEAD -H x-auth-user: myusername -H x-auth-key: mykey "url"
Run Code Online (Sandbox Code Playgroud)
什么是在红宝石中做到这一点的最好方法?用这个宝石?或者我可以手动执行以获得更多控制权.
Mau*_*res 50
你可以做你想做的事:
response = RestClient.post(
url,
request,
:content_type => :json, :accept => :json, :'x-auth-key' => "mykey")
Run Code Online (Sandbox Code Playgroud)
小智 21
你也可以这样做
RestClient::Request.execute(
:method => :get or :post,
:url => your_url,
:headers => {key => value}
)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
33012 次 |
| 最近记录: |