Playwright POST 请求错误:“缺少必需的请求正文”

问题描述 投票:0回答:1
我在使用

request.post()

 方法发送 POST 请求时遇到 Playwright 问题。但是,当我使用 Postman 发送相同的请求时,我正确地收到了响应。

这是我收到的错误消息:

回应:

{ "message" : "Required request body is missing: public org.springframework.http.ResponseEntity<org.scd.model.User>)", "errorCode" : "BAD_REQUEST", "validationErrors" : [ ] }
编剧代码:

test("POST Create Post request", async ({ request }) => { const raw = JSON.stringify({ "iban": "DE8123456781234567898", "creditor": "", "accountHolder": "Max Miller", "signatureDate": "2024-02-21T06:21:57.306Z", "signatureLocation": "Reynoldston", }); const headers = { 'Authorization': `Bearer ${accessToken}`, 'Content-Type': 'application/json', }; const createPostRequestUrl = 'https://test.system.companyname.io/service/v1/872f774d-12d34-67jj4-abcde-4566743450/mandate'; // Make the actual request const response = await request.post(createPostRequestUrl, { headers: headers, body: raw }); // Process the response const responseBody = await response.text(); console.log(responseBody); });

spring-boot rest post playwright
1个回答
0
投票
从 Playwright 版本 1.42.1 开始,文档指出有效负载应使用“数据”属性。

https://playwright.dev/docs/api-testing

test('should create a bug report', async ({ request }) => { const newIssue = await request.post(`/repos/${USER}/${REPO}/issues`, { data: { title: '[Bug] report 1', body: 'Bug description', } }); expect(newIssue.ok()).toBeTruthy(); const issues = await request.get(`/repos/${USER}/${REPO}/issues`); expect(issues.ok()).toBeTruthy(); expect(await issues.json()).toContainEqual(expect.objectContaining({ title: '[Bug] report 1', body: 'Bug description' })); });
这是文档中的直接引用,但您可以看到正在使用的数据属性。不是“身体”属性。

我希望这个答案可以帮助任何发现自己在这里的人。

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