我正在使用 RESTAssured 进行 api 测试。当我使用 Postman 测试 API 登录端点时,我得到了用于防伪的 cookie,Postman(和浏览器)在使用应用程序时每次调用都会使用这些 cookie。
要复制此行为以进行 API 测试,我可以调用进行身份验证,但 RESTAssured 不会像 Postman 那样检索服务器发送的 cookie。
如何为后续 API 调用检索 cookie?
到目前为止,我已经尝试过 Postman 和 RESTAssured,但可以灵活地使用 API 测试库。
httpReq = RestAssured.given().log().all();
httpReq.contentType(ContentType.URLENC.withCharset("UTF-8"));
httpReq.formParam("Email", email);
httpReq.formParam("Password", password);
httpReq.formParam("__RequestVerificationToken", substr);
Map<String, String> authCookies = response.getCookies();
当我调试和观看 authCookies 时,它缺少相关的防伪令牌。将 authCookies 添加到后续请求会导致 401 Bad Request。