api - 赛普拉斯:API 请求的身份验证令牌在哪里?
问题描述
我正在尝试通过需要身份验证的 API 请求数据。我有令牌,我知道如何使用邮递员等手动工具来实现它......
如何使用赛普拉斯格式化身份验证?
it('GET - read', () => {
cy.request({
method: 'GET',
url: 'https://mailtrap.io/api/v1/inboxes/123/messages?page=1&last_id=&useremail',
headers: {
Key: 'Api-Token',
Value: '1234'
}
})
})
})
回复:
The response we got was:
Status: 401 - Unauthorized
解决方案
根据Mailtrap 文档,发送标头Api-Token: {api_token}
应该发送经过身份验证的请求。你可以写:
cy.request({
method: 'GET',
url: 'https://mailtrap.io/api/v1/inboxes/123/messages?page=1&last_id=&useremail',
headers: {
'Api-Token': 'Your Token value' //Replace with real token
},
failOnStatusCode: false
}).then((res) => {
expect(res.status).to.equal(200) //Replace with releveant 2xx response code
})
推荐阅读
- c# - 如何在 C#/Vb.net 中将数组字节写入 PDF/A-3 和附件 [关闭]
- excel-formula - 使用单元格填写 SUMPRODUCT 公式的文件路径?
- java - 尝试通过 ResourceLink 访问 Tomcat 数据源正在返回 ResourceRefLink
- sql - 创建一个具有 NULL 值/0 的数组并查找不包括 null/0 的数组长度
- twilio - Chrome 71 AudioContext 使用 Twilio 客户端恢复
- arrays - ColdFusion 处理数据表“发送参数”
- javascript - 调用方法作为图像源时的 ExpressionChangedAfterItHasBeenCheckedError
- flutter - 如何制作选框颤动图像小部件
- html - 使用线性渐变再现 SVG 渐变等价于 CSS 渐变
- javascript - 如何更改模式的此代码以使其与类而不是 href 一起使用?