无法使用REST Assured生成Auth令牌

时间:2019-02-15 02:49:42

标签: rest-assured

我正在尝试为机器本地生成的API生成访问令牌。我能够使用Postman检索访问令牌。但是我无法使用RestAssured做同样的事情。

下面是我为此写的代码段。

Response authentication = RestAssured.given().auth()
.basic("admin", "password123").header("content-type", "application/json")
.when()
.post("http://localhost:3001/auth/");

响应:

 {"reason":"Bad credentials}

如果其中缺少任何内容,请帮助我找出答案。

1 个答案:

答案 0 :(得分:1)

 Response authentication = RestAssured.given().auth().preemptive()
 .basic("admin","password123")
 .header("content-type", "application/json")
 .when().post("http://localhost:3001/auth");

https://github.com/rest-assured/rest-assured/wiki/Usage#basic-authentication

相关问题