在这种情况下如何使用基本身份验证与放心

问题描述 投票:0回答:2

我正在尝试使用 RestAssured 进行身份验证。 这是我的代码不起作用:

public static void authenticate(){

RestAssured.baseURI = "https://randomUrl/login";
RequestSpecification request = RestAssured.given().auth().basic("[email protected]", "password123");
Response response = request.get();
System.out.println(response.asString());}

这不起作用的一个重要原因是我遗漏了某些东西,因为当我在 Postman 中查看实际请求时,选项卡中有更多信息,如下所示:

Authorization: Basic Auth: 
Username:"client"
Password:"pass"

Headers: 
Authorization: Basic Y2xpZW50OnBhc3N3b3Jk
Content-Type: application/x-www-form-urlencoded

Body:
username:"[email protected]"
password:"password123"
grant_type:"password"

我的问题是我的代码中缺少哪些部分以及如何集成它们以使授权有效?

authentication authorization rest-assured
2个回答
2
投票

REST Assured 在使用基本身份验证时不会发送凭据,除非受到服务器的质询。如果服务器不挑战,则不会发送。如果是这种情况,您可以使用抢占式基本身份验证:

RestAssured.given().auth().preemptive().basic("[email protected]", "password123")

0
投票

我希望下面的代码可以帮助您解决身份验证问题 给定().relaxedHTTPSValidation().auth().preemptive().basic(“用户名”,“令牌(采用base 64加密”)

© www.soinside.com 2019 - 2024. All rights reserved.