如何在Insomnia中提取头部位置URL的一部分作为变量。

huangapple go评论110阅读模式
英文:

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:

  1. First Request: https://domain-1.com
    Response Header Location: https://domain-2.com/tickets/ABC-1234

  2. 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}}

huangapple
  • 本文由 发表于 2023年6月15日 01:15:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/76476058.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定