12

我有兴趣在使用 ruby​​ RestClient gem 时设置自己的用户代理。

http://github.com/archiloque/rest-client

但是,我找不到任何有关如何执行此操作的文档。任何指针?

4

2 回答 2

19
RestClient.get 'http://localhost', :user_agent => "myagent"

https://github.com/rest-client/rest-client/blob/master/lib/restclient.rb

于 2012-08-10T10:36:50.870 回答
0

不确定接受的答案是否非常清楚。用户代理仅由请求的标头设置。我在来源:user_agent中看到的是,他们通过为请求设置标头来设置默认用户代理。这取决于您使用 API 的方式以及如何设置它。请参阅#default_headers链接源文件中的方法。

于 2016-03-28T20:40:09.350 回答