Home Web Front-end JS Tutorial How does Postman transfer token parameters?

How does Postman transfer token parameters?

Apr 08, 2018 pm 04:51 PM
postman token

This time I will show you how Postman transfers token parameters. What are the precautions for Postman when transferring token parameters? The following is a practical case, let's take a look.

Problem description:

There is a login interface to obtain the token, and you must bring the token when accessing other interfaces again

Solution:

1. Set the Postman environment variable (Environment) after accessing the login interface, for example

Set the environment variable Name: token, The value is the token value in responseBody after successful access to the login interface. Please see the detailed description below for how to set it.

2. When accessing other interfaces, the token value can be directly read from the variable. The syntax for obtaining variables in Postman is: {{

Variable name}}

Specific steps:

1. Introduction to the login interface

As shown in the figure, the JSON format of the login interface return value is roughly:

{
  "status": 0,
  "message": "成功",
  "data": {
    "username": "cams_admin_dev",
    "token": "eyJhbGciOiJIUzUxMiJ9.eyJleHAiOjE1MTYzNDIxMjAsInN1YiI6ImNhbXNfYWRtaW5fZGV2IiwiY3JlYXRlZCI6MTUxNjI1NTcyMDU0NywiZnVsbCI6ImNhbXNfYWRtaW5fZGV2IiwidWF1dGgiOiIvKio7QUxMIiwiYXV0aCI6InNldHRpbmdzLGNhbXNfYWRtaW4saW5kdXN0cnksYm9uZCxjYW1zSG9tZSxjb21wYW55LGFyZWEsZGV0YWlscyxjYW1zT3BlcmF0aW9uIn0.pI09X8KNoIK0fb6xC1xbrSZyg-EnUnlZ_9shmOQCRDtdIIEA5iyq3HmzgSx0ReaChEAZxkrrSRTtSXE8ZlbCTw"
  }
}
Copy after login
The return value contains the token value , how can this value be automatically set as a Postman environment variable after accessing the login interface?

2. After accessing the login interface, it is automatically set to the Postman environment variable

Write the following code in the Tests of the Postman software to set the environment variable

pm.test("Status code is 200", function () { 
  pm.response.to.have.status(200); 
}); 
 
// 把responseBody转为json字符串 
var data = JSON.parse(responseBody); 
// 设置环境变量token,供后面的接口引用 
pm.environment.set("token", data.data.token);
Copy after login
As shown in the figure below:

After clicking the Send button to send the request, you can dynamically set the environment variable named token with the value of the token value.

After the setting is successful, click the eye icon and view the variables as shown in the figure:

3. Access other interfaces, environment variable token

As shown in the red mark

1. Another interface

2. Select the token type in TYPE. What I use here is Bearer Token

3. Set the token value in the red marked part on the right. The format is: {{token}} to get the previous login interface. If the token is dynamically set during access, then this interface can be used.

Click Send and the access will be successful.

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

How to use content filters in jQuery

How Vue uses CDN to optimize first screen loading speed

The above is the detailed content of How does Postman transfer token parameters?. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What to do if the login token is invalid What to do if the login token is invalid Sep 14, 2023 am 11:33 AM

Solutions to invalid login token include checking whether the Token has expired, checking whether the Token is correct, checking whether the Token has been tampered with, checking whether the Token matches the user, clearing the cache or cookies, checking the network connection and server status, logging in again or requesting a new Token. Contact technical support or developers, etc. Detailed introduction: 1. Check whether the Token has expired. The login Token usually has a validity period set. Once the validity period exceeds, it will be considered invalid, etc.

How to solve the problem of invalid login token How to solve the problem of invalid login token Sep 14, 2023 am 10:57 AM

The problem of invalid login token can be solved by checking the network connection, checking the token validity period, clearing cache and cookies, checking login status, contacting the application developer and strengthening account security. Detailed introduction: 1. Check the network connection, reconnect to the network or change the network environment; 2. Check the token validity period, obtain a new token, or contact the developer of the application; 3. Clear cache and cookies, clear browser cache and Cookie, and then log in to the application again; 4. Check the login status.

How to solve the problem of storing user tokens in Redis How to solve the problem of storing user tokens in Redis May 31, 2023 am 08:06 AM

Redis stores user tokens. When designing a system similar to e-commerce, a common requirement is that each page needs to carry logged-in user information. There are two common solutions: using cookies to save and using JWT to save. But if Redis cache is used in the system, there is also a third solution - caching the user token in Redis. Generate a token when logging in and store it in Redis //Generate a token object and save it in redis redisTemplate.opsForHash().put("token","user",user)

How Vue3+Vite uses dual tokens to achieve senseless refresh How Vue3+Vite uses dual tokens to achieve senseless refresh May 10, 2023 pm 01:10 PM

1. Token login authentication jwt: JSONWebToken. It is an authentication protocol that is generally used to verify the requested identity information and identity permissions. Composed of three parts: Header, Hayload, Signatureheader: that is, the header information, which is the basic information describing this token, json format {"alg":"HS256", //indicates the signature algorithm, the default is HMACSHA256 (written as HS256) "type":"JWT"//Indicates the type of Token. JWT tokens are uniformly written as JWT}pa

How to solve C++ syntax error: 'expected primary-expression before ':' token'? How to solve C++ syntax error: 'expected primary-expression before ':' token'? Aug 26, 2023 pm 04:06 PM

How to solve C++ syntax error: 'expectedprimary-expressionbefore':'token'? Syntax errors are a common problem in C++ programming. One of the common errors is the "expectedprimary-expressionbefore':'token" error message. This error usually occurs when using conditional expressions and the ternary operator. This article will introduce the cause of this error

Is the domestic API management tool Apifox easy to use? Is the domestic API management tool Apifox easy to use? Jul 26, 2022 pm 08:44 PM

Apifox is an integrated collaboration platform for API documentation, debugging, Mock, and testing, positioning Postman + Swagger + Mock + JMeter. Through one system and one data, we can solve the problem of data synchronization between multiple systems. As long as the API document is defined, API debugging, API data mocking, and API automated testing can be used directly without defining it again;

Andrew Ng's ChatGPT class went viral: AI gave up writing words backwards, but understood the whole world Andrew Ng's ChatGPT class went viral: AI gave up writing words backwards, but understood the whole world Jun 03, 2023 pm 09:27 PM

Unexpectedly, ChatGPT would still make stupid mistakes to this day? Master Ng Enda pointed it out at the latest class: ChatGPT will not reverse words! For example, let it reverse the word lollipop, and the output is pilollol, which is completely confusing. Oh, this is indeed a bit surprising. So much so that after a netizen who listened to the class posted a post on Reddit, it immediately attracted a large number of onlookers, and the post quickly reached 6k views. And this is not an accidental bug. Netizens found that ChatGPT is indeed unable to complete this task, and the results of our personal testing are also the same. △The actual test of ChatGPT (GPT-3.5) and even many products including Bard, Bing, Wen Xinyiyan, etc. does not work. △Actual test Bard△Actual test Wenxinyiyan

What does token mean? What does token mean? Feb 29, 2024 am 10:19 AM

Token is a kind of virtual currency. It is a digital currency used to represent user permissions, record transaction information, and pay virtual currency. Token can be used to conduct transactions on a specific network, it can be used to buy or sell specific virtual currencies, and it can also be used to pay for specific services.

See all articles