简体   繁体   English

空手道:无法将从一个 api 响应中提取的 header 值传递到另一个 Z8A5DA52ED126447D 的请求 header 中

[英]Karate: Not able to pass header value extracted from one api response into the request header of another api

Here I'm storing the value of Etag into variable etag, here the values is printed correctly:这里我将 Etag 的值存储到变量 etag 中,这里的值打印正确:

Given path '/price/v4/quote/',quoteId,'/products'给定路径 '/price/v4/quote/',quoteId,'/products'

And request requestPayload并请求 requestPayload

When method POST当方法 POST

  • print 'headers:', karate.prevRequest.headers打印 'headers:', karate.prevRequest.headers

Then status 200然后状态 200

And def etag = responseHeaders['ETag']和 def etag = responseHeaders['ETag']

  • print etag [print] ["3"]打印 etag [打印] [“3”]

Now I'm passing it to the request header of another api:现在我将它传递给另一个 api 的请求 header:

* header If-Match = etag
Given path '/price/v4/quote/',quoteId,'/accept'
And request requestPayload
When method PUT
* print 'headers:', karate.prevRequest.headers
Then status 200
* print karate.pretty(response)

But I'm getting following error as the value of etag header comes with regex:但是我收到以下错误,因为 etag header 的值带有正则表达式:

Got invalid quoteVersion for quote 'b25f50bc-0479-4390-b4fe-0620fc6c6139'. quoteVersion '[\"3\"]', actualVersion '3'"}

I think you missed that responseHeaders is a Map of List s.我认为您错过了responseHeadersListMap Refer the docs: https://github.com/karatelabs/karate#responseheaders参考文档: https://github.com/karatelabs/karate#responseheaders

Try this:尝试这个:

And def etag = responseHeaders['ETag'][0]

Also we have a better API for headers in the next versions for anyone else coming across this in the future, please refer: https://github.com/karatelabs/karate/issues/1962此外,我们还有一个更好的 API 用于下一个版本中的标头,以供将来遇到此问题的任何人参考: https://github.com/karatelabs/karate/issues/1962

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从 API 登录响应中获取令牌并传递给 API header 请求 Xamarin 中其他菜单的 Header Forms - get token from API Login Response and pass to API header request Header of other Menu in Xamarin Forms 如何从请求中提取“响应”的值,然后在后续请求中将其用作RESTUI的SOAPUI和POSTMAN中的标头 - How can I extract the value of the 'response' from a request and then use it in subsequent requests as Header in SOAPUI and POSTMAN for rest api 空手道 Api 测试 - 如何将数据从一个特征文件传递到另一个特征文件 - Karate Api Testing - How to pass data from one feature file to another How to use one REST API RESPONSE property, and use it in another REST API header property - How to use one REST API RESPONSE property, and use it in another REST API header property 带有API的Ruby传递标头 - Ruby pass header with API Laravel API标头请求 - Laravel api header request 响应头中的 API 响应时间 - API response time in response header 将 api 响应从一个组件传递到 Angular 中的另一个组件 - Pass api response from one component to another component in Angular 如何使用 Node 将数据从一个 API 请求传递到另一个请求 - How to pass data from one API request to another with Node 如何通过位置 header 响应命令(API)和查询(odata)控制器 - How to pass Location header to response with command(API) and query(odata) controllers
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM