如何使用 restAssured 将最新的 cookie 设置为 header

how to set latest coockie as header using restAssued

场景如下: 我有两个URL URL1 = https://someurl.com URL2(网络服务URL)=https://jira/something/j2/projectstatus?projectID=12345

现在,如果我使用有效 usedID/password 在 chrome 上登录到 URL1,如果我直接点击 chrome 的第二个选项卡上的 URL2浏览器。我得到一些回应。

但是,如果我不登录 URL1 并尝试在 chrome 上点击 URL2,我得到的响应是 {错误:您没有登录权限; ErrorID:ERROR}

我没有关于此 Web 服务的任何 header 信息

Plesae 建议如何使用 cookie 放心地点击 URL2 作为 header。

您可以使用 RestAssured 为第二个请求设置 cookie,例如:

Cookie userNameCookie = new Cookie.Builder("username", "some_value")
                .setSecured(true)
                .setComment("some comment")
            .build();
Cookie pwdCookie = new Cookie.Builder("password", "some_value")
                .setSecured(true)
                .setComment("some comment")
            .build();
Cookies cookies = new Cookies(userNameCookie, pwdCookie);

Response response = given().port(port).cookies(cookies).when().get("request URL");