intellij-idea - Setting variables from the response in IntelliJ IDEA's HTTP request generator
问题描述
I am enjoying IntelliJ IDEA's HTTP request generator as an alternative to Postman etc.
Currently, my application uses an ephemeral key for JWTs. You know what kind of pain it is... Every time you restart the application you MUST authenticate again, even if the old token is still (temporally) valid.
Currently I have to run my OAuth authentication request with my credentials, copy-and-paste the JWT from the output JSON, and then paste in into next request's Authorization
header
GET http://localhost:8080/api/auth/v1/token Authorization: CCB [... static token...]
{
"id_token": "eyJhbGciOiJIUzI1NiJ9....", <== copy that!
"refresh_token": "eyJhbGciOiJIUzI1NiJ9....",
"expires_in": 1634292409144,
"user_details": {
And
PATCH http://localhost:8080/api/v1/example/runImportJob Authorization: Bearer <== paste!
Question
I know that IntelliJ IDEA supports {{variables}}
. I'd like to ask if it is possible to set the output of the token invocation into a variable which I'll then reference in the Authorization header
Desiderata
PATCH http://localhost:8080/api/v1/example/runImportJob
Authorization: Authorization {{jwt}}
And to run the authentication request (GET .../token
) which ultimately sets the jwt variable, after jsonpath-ing the response of corse
解决方案
您可以尝试使用client.global.set和client.global.get来保存/加载变量。请参阅https://www.jetbrains.com/help/idea/http-response-handling-examples.html#script-var-example上的示例。
推荐阅读
- angular - SignalR Asp.netcore and angular ( WebSocket is not in the OPEN state) disconnection for signalR.HttpTransportType.WebSockets
- ruby - Karafka start_from_beginning not working as expected
- android - 调用 ContentObserver 时更新设备联系人的 PagedList
- python - How to read commented text from XML file in python
- java - How to create endpoint that returns responseentity by calling external endpoint
- exchange-server - Are Exchange IPM.Contact properties 0x8043 and 0x8044 documented?
- python - 如何将布尔真值输入变量?
- python - 在逗号分隔列表中搜索字符串
- openxml - 获取节点上预期的可能元素列表
- c# - 在 Abp 模块中使用 AbpCastleLog4NetModule