Intellij HTTP客户端保存JSON值作为变量不适用于可变名称的可变名称

发布于 2025-02-13 11:59:14 字数 500 浏览 1 评论 0原文

我的获取请求:

GET {{Endpoint}}/tokens/v1/id
Content-Type: application/json

> {% client.log(response.body.no-claim); %}

响应正文:

{
  "documentation": "roofs",
  "no-claim": "eyJ0eXAiOiJKV1QiLCJhbGc"
}

响应处理程序的错误:

ReferenceError: "claim" is not defined. (<jsHandler script>#143)Script finished

如果我尝试提取文档的值,它可以正常工作,但不适用于“无主张”。

我尝试将其包装在单个/双引号中,并将其保存到Env变量并将ENV变量作为{{not-claim}}传递给ENV变量,它们都无法使用。

My GET Request:

GET {{Endpoint}}/tokens/v1/id
Content-Type: application/json

> {% client.log(response.body.no-claim); %}

Response body:

{
  "documentation": "roofs",
  "no-claim": "eyJ0eXAiOiJKV1QiLCJhbGc"
}

Error from Response handler:

ReferenceError: "claim" is not defined. (<jsHandler script>#143)Script finished

If I try to extract value of documentation it works fine but not working for "no-claim".

I tried wrapping it within single/double quotes and also saving it to env variable and passing the env variable as {{no-claim}}, none of them worked.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一城柳絮吹成雪 2025-02-20 11:59:14

这是JavaScript。您可以使用响应。Body['id-claim']语法。 https://developer.mozilla.org/en-us/docs/web/javascript/referent/referation/property_accessors#syntax

例如,下一个请求正常:

POST https://httpbin.org/post
Content-Type: application/json

{
"my-json-value": "value"
}

{%
// 'json' is a property in HTTPBin response JSON
client.log(response.body.json["my-json-value"])
%}

It is JavaScript. You can use response.body['id-claim'] syntax. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_Accessors#syntax

For example, the next request works fine:

POST https://httpbin.org/post
Content-Type: application/json

{
"my-json-value": "value"
}

{%
// 'json' is a property in HTTPBin response JSON
client.log(response.body.json["my-json-value"])
%}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文