在 Cypress JS 中使用 --data-raw 发布请求
再会!
我在 JS cypress 上的自动测试有问题。 我需要在自动测试中发送发布请求。这是我用手发送的:
curl --location --request POST 'http://test.com/service' \
--header 'Token: n7n7n7n7n7' \
--header 'Content-Type: text/plain' \
--data-raw 'text: v3'
这是我尝试在 js 测试中发送帖子的方式:
cy.request({
method: 'POST',
url: 'http//:test.com/service',
headers: {
'Token': n7n7n7n7n7,
'Content-Type':'text/plain'
},
data: "text: v3"
}).then((res)=>{
expect(res.status).to.eq(200)
})
它不起作用,而不是 200,我得到 400,在 cypress 日志中我看到:
我们发送的请求是:
方法:POST 网址:http://:test.com/service 标题:{ “连接”:“保持活动”, "X-Gitlab-Token": "n7n7n7n7n7", “内容类型”:“文本/纯文本”, “用户代理”:“Mozilla/5.0”, “接受”: ”/”, "accept-encoding": "gzip, deflate", “内容长度”:0 并且
没有数据。
如何在 cypress 请求中发送原始数据? 提前致谢!
Good day!
I have a problem with my autotest on JS cypress.
I need to send post request in autotest. Here it is as I send it by hands:
curl --location --request POST 'http://test.com/service' \
--header 'Token: n7n7n7n7n7' \
--header 'Content-Type: text/plain' \
--data-raw 'text: v3'
This is how I try to send post in js test:
cy.request({
method: 'POST',
url: 'http//:test.com/service',
headers: {
'Token': n7n7n7n7n7,
'Content-Type':'text/plain'
},
data: "text: v3"
}).then((res)=>{
expect(res.status).to.eq(200)
})
It doesnt work, instead of 200 I get 400, in cypress log I see:
The request we sent was:
Method: POST
URL: http//:test.com/service
Headers: {
"Connection": "keep-alive",
"X-Gitlab-Token": "n7n7n7n7n7",
"Content-Type": "text/plain",
"user-agent": "Mozilla/5.0",
"accept": "/",
"accept-encoding": "gzip, deflate",
"content-length": 0
}
And no data.
How can I send data-raw in cypress request?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
让我们尝试一下脚本:
cy.请求({
方法:'POST',
url: 'http://:test.com/service',
标题:{
'授权': "n7n7n7n7n7",
'内容类型':'文本/纯文本'
},
正文:{“文本”:“v3”}
}).then((res)=>{
期望(res.status).to.eq(200)
})
Let's try with the script:
cy.request({
method: 'POST',
url: 'http//:test.com/service',
headers: {
'authhorization': "n7n7n7n7n7",
'Content-Type':'text/plain'
},
body: {"text": "v3"}
}).then((res)=>{
expect(res.status).to.eq(200)
})