This guide explains how to set, change, and rotate the User-Agent header in Postman to avoid anti-bot detection and improve your HTTP requests:
- What Is the Postman Default User Agent?
- Change the Postman User Agent
- Implement User Agent Rotation in Postman
The User-Agent
header identifies the client making an HTTP request. It typically includes details about the client’s machine and the application used for the request. Web browsers, HTTP clients, and other software set this header automatically.
Here’s an example of a User-Agent
string used by Chrome when requesting a web page:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36
A browser's User-Agent
header consists of several key components:
Mozilla/5.0
– Originally signaled Mozilla compatibility; now included for broader support.Macintosh; Intel Mac OS X 10_15_7
– Indicates the operating system (Mac OS X 10.15.7
) and platform (Intel Mac).AppleWebKit/537.36
– Specifies the rendering engine used by Chrome.(KHTML, like Gecko)
– Ensures compatibility with KHTML and Gecko layout engines.Chrome/127.0.0.0
– Represents the browser name and version.Safari/537.36
– Suggests compatibility with Safari.
Servers use the User-Agent
header to identify whether a request comes from a browser or another source.
A common mistake among web scraping bots is using default or non-browser User-Agent
strings, which anti-bot protections easily detect and block.
Postman is a widely used desktop HTTP client. Like most HTTP clients, it automatically sets a default User-Agent
header in each request.
You can observe this behavior by inspecting the auto-generated headers in Postman.
As you can see, the Postman default user agent follows this format:
PostmanRuntime/x.y.z
The PostmanRuntime/x.y.z
string indicates a request made by Postman, where x.y.z
represents the version number.
To confirm this, send a GET request to httpbin.io/user-agent
. This endpoint returns the User-Agent
header of the incoming request, allowing you to verify the user agent used by any HTTP client.
Notice how the user agent returned by the API matches the one set by Postman by default. In detail, the Postman user agent is:
PostmanRuntime/7.41.0
Postman’s User-Agent
differs from browser headers, making requests more likely to be blocked by anti-bot systems. These systems detect bot-like patterns, including unusual user agents. Changing the default User-Agent
helps avoid detection.
Postman allows you to change the user agent on a single HTTP request by manually specifying a User-Agent
header.
Note:
The Postman auto-generated headers cannot be directly modified.
Go to the “Headers” tab and add a new User-Agent
header:
Postman replaces its default User-Agent
with your custom header. Since HTTP headers are case-insensitive, you can use User-Agent
, user-agent
, or any variation.
Verify the change by sending a GET request to httpbin.io/user-agent
.
A Postman collection is a group of API requests with shared configurations. Postman allows defining custom scripts that run before or after each request in a collection.
To apply a custom User-Agent
to all requests, log in to your Postman account or create one.
Assume you have an "HTTPBin" collection with organized HTTPBin endpoints:
Execute the request for the /user-agent
endpoint, and you will get the default Postman user agent:
A pre-request script is a JavaScript function that runs before each request in a Postman collection. You can use it to set a custom User-Agent
header.
To create a pre-request script:
- Open your collection.
- Navigate to the Scripts tab.
- Select the Pre-request option.
In the editor, paste the following code:
pm.request.headers.add({
key: "User-Agent",
value: "<your-user-agent>"
});
Replace the <your-user-agent>
string with the value of the user agent you want to use, as below:
pm.request.headers.add({
key: "User-Agent",
value: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36"
});
pm.request.headers.add()
is a special function from the Postman API to add a specific header to the request.
Click the “Save” button to apply the changes.
Execute the request for the /user-agent
endpoint again:
This time, the returned user agent will be the one set in the script and not the default Postman one.
The User-Agent
auto-generated header is optional, and you can actually uncheck it. When unchecked, Postman will no longer send a User-Agent
header.
Verify that by sending a request to the httpbin.io/headers
endpoint, which returns all the headers of the incoming request:
Note that the headers object returned by the endpoint does not include the User-Agent
key.
Note:
Unsetting the
User-Agent
header is not recommended, as nearly web requests typically include that header.
Simply replacing Postman’s User-Agent
with a browser string may not bypass anti-bot systems, especially when making repeated requests from the same IP.
To avoid detection, use user agent rotation, assigning a different User-Agent
to each request. This reduces the likelihood of being flagged as a bot.
Let's learn how to implement user agent rotation in Postman.
Visit a site like WhatIsMyBrowser.com and populate a list of valid user agents:
const userAgents = [
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36 Edg/127.0.2651.86",
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36 Edg/127.0.2651.86",
"Mozilla/5.0 (Linux; Android 10; HD1913) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.6533.103 Mobile Safari/537.36 EdgA/127.0.2651.82",
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36",
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36",
"Mozilla/5.0 (iPhone; CPU iPhone OS 17_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/127.0.6533.107 Mobile/15E148 Safari/604.1",
"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:129.0) Gecko/20100101 Firefox/129.0",
"Mozilla/5.0 (Macintosh; Intel Mac OS X 14.6; rv:129.0) Gecko/20100101 Firefox/129.0",
// other user agents...
];
Tip:
The more real-world user agents this array contains, the better to increase the rotation chances.
Use the JavaScript Math
API to randomly select a user agent from the list:
const userAgent = serAgents[Math.floor(Math.random() * userAgents.length)];
This is what happens in this line of code:
Math.random()
generates a random number between 0 and 1.- The generated number is then multiplied by the length of the
userAgents
array. Math.floor()
rounds down the resulting number to the largest integer less than or equal to the source number. The resulting number corresponds to an index that goes from 0 touserAgents.length - 1
.- The index is used to access a random item from the array of user agents.
- The randomly selected user agent is assigned to a variable.
Use the pm.request.headers.add()
to define a User-Agent
header with the random userAgent
value:
pm.request.headers.add({
key: "User-Agent",
value: userAgent
});
The HTTP request of the collection will now have a rotating User-Agent
header.
Here is the final Postman pre-request script for user agent rotation:
// a list of valid user agents
const userAgents = [
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36 Edg/127.0.2651.86",
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36 Edg/127.0.2651.86",
"Mozilla/5.0 (Linux; Android 10; HD1913) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.6533.103 Mobile Safari/537.36 EdgA/127.0.2651.82",
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36",
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36",
"Mozilla/5.0 (iPhone; CPU iPhone OS 17_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/127.0.6533.107 Mobile/15E148 Safari/604.1",
"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:129.0) Gecko/20100101 Firefox/129.0",
"Mozilla/5.0 (Macintosh; Intel Mac OS X 14.6; rv:129.0) Gecko/20100101 Firefox/129.0",
// other user agents...
];
// randomly extract a user agent from the list
const userAgent = userAgents[Math.floor(Math.random() * userAgents.length)];
// set the random user agent header
pm.request.headers.add({
key: "User-Agent",
value: userAgent
});
Add the script to your collection and test it by sending requests to httpbin.io/user-agent
. Run multiple requests to observe the rotating user agents in action.
The returned user agent keeps changing.
Overriding the User-Agent
header and implementing user agent rotation helps elude basic anti-bot mechanisms. However, more advanced systems will still be able to block your requests. To prevent IP bans, you could use a proxy in Postman.
Sign up today to start your free trial.