如何在REST Assured中发送带有身份验证标头的GET请求?
我正在尝试使用REST-Assured,JUnit,使用标题“Auth-Service-Id:my_-app”、“Auth-Identifier:blablabla”、“Auth-Secret:myauth-Secret”向URL发送GET请求如何在REST Assured中发送带有身份验证标头的GET请求?,rest,authentication,junit,junit4,rest-assured,Rest,Authentication,Junit,Junit4,Rest Assured,我正在尝试使用REST-Assured,JUnit,使用标题“Auth-Service-Id:my_-app”、“Auth-Identifier:blablabla”、“Auth-Secret:myauth-Secret”向URL发送GET请求 public class RestAPITest { @Test public void getRequestTime() throws URISyntaxException { // Specify the base URL to the
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());
}
您可以使用重启的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");
Map headers=newhashmap();
headers.put(“身份验证服务Id”、“我的应用程序”);
headers.put(“Auth标识符”、“blabla”);
Response Response=restarsured.given(此.requestSpecification)
.标题(标题)
.when()
.get(“https://myurl.com");
如需进一步阅读,请点击链接