简体   繁体   中英

How can you change the User Agent string for a Heroku app?

I've got a Ruby on Rails app running on Heroku. One feature of the app is that it fetches feeds from a webserver. The user agent is simply "Ruby."

I'd like to create a more friendly and informative user agent string for webmasters. Does anyone know how to do this this?

Your HTTP client should have an option for setting request headers. In this case, you'll just need to change the 'User-Agent' header.

If you use Net::HTTP, something like this should work:

req = Net::HTTP::Get.new(uri)
req['User-Agent'] = 'MyApp (see http://example.com)'

res = Net::HTTP.start(uri.hostname, uri.port) {|http|
  http.request(req)
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM