Rest API / Soap UI工具 - 如何在点击终点时手动传递Cookie

问题描述 投票:0回答:2

我是RESTful服务测试的新手,并且卡在哪里建立与端点的连接我需要传递Cookie。我有参数和值但不确定如何在命中请求时手动传递Cookie(而不是通过标题或Groovy脚本)。

rest http cookies http-headers soapui
2个回答
1
投票

TL; DR

就http-request而言,Cookie只是一个名为cookie的头文件和name=value; anothername=anothervalue; yetanotherone=yetanothervalue;格式的header-value

继续阅读

来自https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cookie

Cookie HTTP请求标头包含先前由服务器使用Set-Cookie标头发送的存储的HTTP Cookie。

Cookie标头是可选的,例如,如果浏览器的隐私设置阻止cookie,则可以省略。

How to send Cookie

就像任何其他标题一样。只有条件是,标题名称应为cookie,标题值应为name=value; anothername=anothervalue; yetanotherone=yetanothervalue;格式。

Curl

curl -v --cookie "USER_TOKEN=my-most-secure-session-id" http://localhost:8080/

如果你想让你的curl读取cookie文件并发送它

使用curl -c /path/to/cookiefile http://yourhost/

更多这里:https://curl.haxx.se/docs/http-cookies.html

如何使用SoapUI发送它

Sending cookie as request header in SOAP UI request for rest web service

使用chrome或firefox建立用户会话(登录)并转到开发人员选项卡并复制cookie值,并将其与soapUI请求一起作为标题发送。 (恭喜,你劫持了自己的会话)

对于需要传递cookie的任何测试,在soapUI中,转到testcase选项并打开“维护HTTP会话”。

http://www.soapui.org/soapui-projects/form-based-authentication.html

这是我的Google Chrome开发人员标签,其中显示了stackoverflow页面的请求标头

enter image description here


1
投票

只需发送http标头

Cookie: name=value

到服务器

© www.soinside.com 2019 - 2024. All rights reserved.