繁体   English   中英

如何在REST保证的情况下发送带有身份验证标头的GET请求?

[英]How to send a GET request with Authentication header in REST Assured?

我正在尝试使用REST Assured,JUnit使用标头“ Auth-Service-Id:my_app”,“ Auth-Identifier:blaBlaBlabla”,“ Auth-Secret:myauth-secret”将GET请求发送到URL。

public class RestAPITest {

@Test
public void getRequestTime() throws URISyntaxException {

    // Specify the base URL to the RESTful web service
    Response response = RestAssured.get("https://myurl.com");        
    logger.log(Level.INFO, response.time() + " milliseconds");

    int statusCode = response.getStatusCode();
    logger.log(Level.INFO, "Expected response status code is 200. Recieved response status code is " + statusCode);
    Assert.assertEquals(statusCode, 200);
    logger.log(Level.INFO, "Response Body is " + response.body().asString());
}

您可以使用RestAssured的headers()方法传递标 ,如下所示:

Map<String, String> headers = new HashMap<>();
    headers.put("Auth-Service-Id", "my-app");
    headers.put("Auth-Identifier", "blaBlaBlabla");

Response response = RestAssured.given(this.requestSpecification)
            .headers(headers)
            .when()
            .get("https://myurl.com");

要进一步阅读,请点击链接。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM