通过变量将标题传递给标题

发布于 2025-01-30 16:23:09 字数 877 浏览 5 评论 0原文

将尝试确切地提出问题。对不起,如果不能做到这一点!

从下面给定的链接

https:// restful-booker。 herokuapp.com/apidoc/index.html

使用API​​链接,我想通过首先从“ create create” API生成令牌并将其传递给标题以授权来自动化“更新” API自动化。我在Postman上检查了它的空手道正常工作,我编写了此代码。

* def auth_token = response.token 
Given url 'https://restful-booker.herokuapp.com/booking/5591'
* def request_header = { Accept: '*/*' , Accept-Encoding : 'gzip, deflate, br' , Connection : 'keep-alive', Content-Type : 'application/json' , Accept : 'application/json' , Cookie : 'token=' + auth_token }

变量auth_token正在从第一个API响应中获得令牌,在同一情况下,我试图通过使用上面的标题来运行更新API,但它一直给出此错误,但

net.minidev.json.parser.ParseException: Unexpected token + at position 168.

找不到。一个有效的解决方案,因此在这里放弃问题。

Will try to be precise in asking question. Sorry if couldn't do it up to the mark!

Was given an assignment to automate api from the given below link

https://restful-booker.herokuapp.com/apidoc/index.html

Using the Api chaining I am suppose to automate "Update booking" api by first generating token from "Create Token" api and passing it in headers for authorization. I checked it on postman its working fine there for karate I wrote this code

* def auth_token = response.token 
Given url 'https://restful-booker.herokuapp.com/booking/5591'
* def request_header = { Accept: '*/*' , Accept-Encoding : 'gzip, deflate, br' , Connection : 'keep-alive', Content-Type : 'application/json' , Accept : 'application/json' , Cookie : 'token=' + auth_token }

the variable auth_token is getting token from the first api response and under same scenario I am trying to run update api by using above headers but it keeps giving this error

net.minidev.json.parser.ParseException: Unexpected token + at position 168.

Could not find a valid solution so dropping question here.

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

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

发布评论

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

评论(1

Smile简单爱 2025-02-06 16:23:09

我认为您需要阅读和理解文档,这不是您设置请求标题的方式。这是我认为您正在尝试做的事情,我希望这有助于其他尝试使用此“ Restful Booker”应用程序的人。

Feature:

Scenario:
* url 'https://restful-booker.herokuapp.com'    

* path 'auth'
* request { username: 'admin', password: 'password123' }
* method post
* status 200
* def token = response.token

* header Accept = 'application/json'
* path 'booking'
* request
"""
{
    "firstname" : "Jim",
    "lastname" : "Brown",
    "totalprice" : 111,
    "depositpaid" : true,
    "bookingdates" : {
        "checkin" : "2018-01-01",
        "checkout" : "2019-01-01"
    },
    "additionalneeds" : "Breakfast"
}    
"""
* method post
* status 200

* path 'booking', response.bookingid
* cookie token = token
* method delete
* status 201

I think you need to read and understand the docs, that's not how you set request headers. Here's what I think you were trying to do, and I hope that this helps others who try to use this "Restful Booker" application.

Feature:

Scenario:
* url 'https://restful-booker.herokuapp.com'    

* path 'auth'
* request { username: 'admin', password: 'password123' }
* method post
* status 200
* def token = response.token

* header Accept = 'application/json'
* path 'booking'
* request
"""
{
    "firstname" : "Jim",
    "lastname" : "Brown",
    "totalprice" : 111,
    "depositpaid" : true,
    "bookingdates" : {
        "checkin" : "2018-01-01",
        "checkout" : "2019-01-01"
    },
    "additionalneeds" : "Breakfast"
}    
"""
* method post
* status 200

* path 'booking', response.bookingid
* cookie token = token
* method delete
* status 201
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文