API请求使用Java与剧作家失败
我正在尝试使用Java学习用于API和Web测试的剧作家。到目前为止,通过API测试,我会遇到一个奇怪的问题,在我的所有请求中都会遇到以下错误:
<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx</center>
</body>
</html>
这是我的代码:
Playwright playwright = Playwright.create();
APIRequestContext request;
Map<String, String> headers = new HashMap<>();
headers.put("Content-Type", "application/json");
request = playwright.request()
.newContext(new APIRequest.NewContextOptions()
.setBaseURL("https://petstore.swagger.io/v2/store")
.setExtraHTTPHeaders(headers)
);
Map<String, String> body = new HashMap<>();
body.put("id","400");
body.put("petId","731368479");
body.put("quantity", "4");
body.put("status","placed");
body.put("complete", "true");
APIResponse addNewPet = request.post("/order",
RequestOptions.create().setData(body));
System.out.println(addNewPet.text());
// assertTrue(addNewPet.ok());
// assertEquals(200, addNewPet.status());
playwright.close();
我不确定在哪里和在做什么错。提前致谢。
I am trying to learn Playwright for api and web testing using Java. So far with api testing I am getting a weird issue where I am getting the following errors for all of my requests:
<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx</center>
</body>
</html>
Here is my code:
Playwright playwright = Playwright.create();
APIRequestContext request;
Map<String, String> headers = new HashMap<>();
headers.put("Content-Type", "application/json");
request = playwright.request()
.newContext(new APIRequest.NewContextOptions()
.setBaseURL("https://petstore.swagger.io/v2/store")
.setExtraHTTPHeaders(headers)
);
Map<String, String> body = new HashMap<>();
body.put("id","400");
body.put("petId","731368479");
body.put("quantity", "4");
body.put("status","placed");
body.put("complete", "true");
APIResponse addNewPet = request.post("/order",
RequestOptions.create().setData(body));
System.out.println(addNewPet.text());
// assertTrue(addNewPet.ok());
// assertEquals(200, addNewPet.status());
playwright.close();
I am not sure where and what I am doing wrong. Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您在baseurl的末端添加斜线并将其从邮政URL中删除,则似乎正在工作:
Seems to be working if you add the slash at the end of the baseURL and remove it from the post url: