我对使用ruby RestClient gem时设置自己的用户代理感兴趣。
http://github.com/archiloque/rest-client
但是,我找不到任何有关如何操作的文档。有什么指针吗?
答案 0 :(得分:18)
RestClient.get 'http://localhost', :user_agent => "myagent"
请参阅https://github.com/rest-client/rest-client/blob/master/lib/restclient.rb
答案 1 :(得分:-1)
不确定接受的答案是否清楚。用户代理仅由请求的标头设置。我在sources中看到的是,他们通过将:user_agent
标头设置为请求来设置默认用户代理。这取决于您使用API的方式如何设置它。请参阅链接源文件中的#default_headers
方法。