英文:
How to extract part of header location url as variable in insomnia
问题
我需要提取标头位置URL中的一部分(票号),以便在Insomnia中的另一个请求中使用,但我不知道如何获取它。
到目前为止,我所做的是:
1)第一个请求:https://domain-1.com
响应标头位置:https://domain-2.com/tickets/ABC-1234
2)为第二个请求创建了一个标签 - https://domain-1.com/{response-header}
执行的功能:响应
属性 - 标头
请求 - (另一个URL)
标头名称 - 位置
触发行为 - 当过期时
最大年龄 - 60秒
实时预览:https://domain-2.com/tickets/ABC-1234
但在查询URL上,我得到的是:https://domain-1.com/https://domain-2.com/tickets/ABC-1234
我期望的是:https://domain-1.com/ABC-1234
有人能给我一点提示吗?
英文:
I need to extract part of header location url (ticket number) to use on another request in insomnia, but I have no idea how to get that.
What I did so far was:
-
First Request: https://domain-1.com
Response Header Location: https://domain-2.com/tickets/ABC-1234 -
Created a tag for the second request - https://domain-1.com/{response-header}
Function to perform: Response
Attribute - Header
Request - (the other url)
Header name - Location
Trigger behaviour - when expired
Max age - 60s
Live preview: https://domain-2.com/tickets/ABC-1234
But on the query url, i'm getting: https://domain-1.com/https://domain-2.com/tickets/ABC-1234
And I expect: https://domain-1.com/ABC-1234
Can someone give me a light?
答案1
得分: 0
只找到了解决方案。
创建一个文件夹,将两个请求放入其中,并使用以下信息编辑文件夹环境:
{
"location": "{{% response 'header', 'req_xxxxxxxxxx', 'b64::TG9xxxx', 'when-expired', 60 %}}",
"code": "{{ location | replace('https://domain-2.com/tickets/', '')}}"
}
然后在请求中使用标签 "code":
https://domain-1.com/{{code}}
英文:
Just found the solution.
Create a folder, put the both requests on it and edit folder environment with the information below:
{
"location": "{{% response 'header', 'req_xxxxxxxxxx', 'b64::TG9xxxx', 'when-expired', 60 %}}",
"code": "{{ location | replace('https://domain-2.com/tickets/', '')}}"
}
Then use the tag "code" on request:
https://domain-1.com/{{code}}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论