在 IntelliJ http 请求编辑器中;有没有办法为文件(和全局)中的所有请求设置通用配置?
例如,我想为所有请求指定一个授权标头。
当前代码
GET http://localhost:8080/api/foo
Authorization: Bearer my-token
Run Code Online (Sandbox Code Playgroud)
我试图实现的代码:
合意的代码
<common headers>
Authorization: Bearer my-token
GET http://localhost:8080/api/foo
GET http://localhost:8080/api/bar
GET http://localhost:8080/api/baz
Run Code Online (Sandbox Code Playgroud)
小智 6
有点晚了,但我会尽量给出答案,以防有人过来。
我不确定这正是您要找的东西,但也许会有所帮助。
如果您从登录端点动态获取令牌,则可以将令牌存储在变量中,然后在任何请求中使用它。
例子:
### Login
POST http://localhost:8080/login
Content-Type: application/json
{
"email": "someEmail",
"password": "somePassword"
}
> {%
client.global.set("auth_token", response.headers.valuesOf('x-auth-token')[0]);
%}
### Get user
GET http://localhost:8080/user/someUserId
Authorization: Bearer {{auth_token}}
Run Code Online (Sandbox Code Playgroud)
在这种情况下,我将来自标头的令牌存储x-auth-token
在变量中auth_token
。比我在所有下一个请求的授权标头中使用它。
祝你今天过得愉快!
归档时间: |
|
查看次数: |
2086 次 |
最近记录: |