In Postman, there are many ways to pass parameters, includingparams
andx-www-form-urlencoded
。
These two methods are different in terms of usage scenarios and the way of passing data.
1. Params
Params
Options are used to pass query parameters in the URL. These parameters are usually used for GET requests, but can also be used with other HTTP methods.
Features:
- The parameter is appended as a query string at the end of the URL.
- Suitable for passing non-sensitive data or for operations such as filtering and sorting.
Example:
For a GET request:
/api/users?username=johndoe&age=30
In Postman, you can set it like thisParams
:
- Key:
username
- Value:
johndoe
- Key:
age
- Value:
30
2. x-www-form-urlencoded
x-www-form-urlencoded
Used to pass data in the body of an HTTP request, often used in POST requests.
This format encodes data into key-value pairs, similar to a query string, but the data is in the body of the request instead of the URL.
Features:
- Data is passed in the body of an HTTP request, not in the URL.
- Suitable for passing form data, especially in the case of form submission.
- The data is URL encoded during transmission (for example, encode spaces as
+
or%20
)。
Example:
For a POST request, send the following data:
username=johndoe&age=30
In Postman, you can choosex-www-form-urlencoded
Options and set parameters:
- Key:
username
- Value:
johndoe
- Key:
age
- Value:
30
Example of usage
Suppose we have a user-registered API endpoint and the URL is/api/register
, need to be passedusername
andpassword
。
Using Params
If usingParams
Passing data, the URL of the POST request will become:
/api/register?username=johndoe&password=secret
In Postman:
- choose
Params
Tab. - Add parameters:
- Key:
username
- Value:
johndoe
- Key:
password
- Value:
secret
- Key:
Using x-www-form-urlencoded
If usingx-www-form-urlencoded
Passing data, the URL requested by POST is still/api/register
, but the data is passed in the request body.
In Postman:
- choose
Body
Tab. - choose
x-www-form-urlencoded
。 - Add parameters:
- Key:
username
- Value:
johndoe
- Key:
password
- Value:
secret
- Key:
Summarize
- Params: Used to pass query parameters in URLs, suitable for GET requests and non-sensitive data.
- x-www-form-urlencoded: Used to pass data in the request body, suitable for POST request and form data.
Which method to choose depends on the specific usage scenario and data type.
The above is personal experience. I hope you can give you a reference and I hope you can support me more.