Using request is it possible to set the user agent for every request?
Currently I have to set it at the time of making the request:
request.post(url, { form: form, headers: { 'User-Agent': ua }}, function(err, resp, body) {
// Do some stuff
})
Is it possible?
To set a custom user agent, include an agent string in the HTTP header User-Agent. For the integration name, use a string that clearly and meaningfully identifies your integration. For the integration version, use a build ID, commit hash, or other identifier that is updated when you release new integration versions.
Use requests. get() to set the user agent Define a dictionary with a key "User-Agent" set to the desired user agent. Call requests. get(url, headers=headers) with url as the target URL and headers as the dictionary of the previous step to set the user agent in a request.
1) the default user agent is python-requests/2.25.
You can create a request method with your own defaults:
var customHeaderRequest = request.defaults({
headers: {'User-Agent': ua}
})
Then use it:
customHeaderRequest.post(url)
see https://www.npmjs.com/package/request#requestdefaultsoptions
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With