How to set a custom user agent in ruby

后端 未结 4 537
我在风中等你
我在风中等你 2020-12-31 01:32

I\'ve a task to test different user agents on a URL through automation. I\'m using ruby to code, and I\'ve been trying to set an user agent using the following method, but i

4条回答
  •  既然无缘
    2020-12-31 01:55

    http = Net::HTTP.new("your.site.com", 80)
    req = Net::HTTP::Get.new("/path/to/the/page.html", {'User-Agent' => 'your_agent'})
    response = http.request(req)
    puts response.body
    

    Works great for me.

提交回复
热议问题