我正在为我的Node后端API编写一个Cypress测试.测试发送一个带有一些Header和Body的POST请求,其中包含一些后台使用所需的参数.
奇怪的是,终结点只接收到空的request.body
.
这是我的Cypress测试的样子,您可以看到我是如何发送请求正文的:
it('onboards a repo - POST', () => {
cy.request({
method: 'POST',
url: `/my/${org}/endpoint`,
headers: headers,
body: {
productId: productId,
requestorEmail: requestorEmail
}
}).then( (response) => {
expect(response.status).to.eq(200);
});
});
Edit:以下是我要发送的标题:
const headers = {
'Accept': 'application/json',
'Content-Type': 'application/json, text/plain',
'Authorization': 'Bearer <MY_TOKEN>',
};
你知道为什么我在后台没有收到request.body
以内的任何东西吗?