[英]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
Then status 200然后状态 200
And def etag = responseHeaders['ETag']和 def etag = responseHeaders['ETag']
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.我认为您错过了responseHeaders
是List
的Map
。 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.