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

发布于 2025-01-26 02:13:02 字数 963 浏览 3 评论 0原文

我正在尝试将身份验证与重新确定。 这是我的代码不起作用:

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"

我的问题是我的代码中缺少什么作品,如何整合它们以使授权起作用?

I am trying to use authentication with RestAssured.
Here is my code that does not work:

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());}

A big reason for which this does not work is that I am missing certain things because when I look at the actual request in Postman, there is more info in the tabs there as follows:

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"

My question is what are the missing pieces in my code and how do integrate them so that the authorization works?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

心的憧憬 2025-02-02 02:13:02

请放心,除非服务器挑战,否则使用基本身份验证时不会发送凭据。如果服务器没有挑战,则不会发送。如果是这种情况,您可以使用先发制的基本身份验证:

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

REST Assured doesn't send the credentials when using basic authentication unless it's challenged by the server. If the server doesn't challenge, it won't send it. If this is the case you can use preemptive basic authentication:

RestAssured.given().auth().preemptive().basic("[email protected]", "password123")
罪歌 2025-02-02 02:13:02

我希望以下代码可以帮助您解决身份验证问题
给定()。selieedhttpsvalidation()。auth()。

I hope below code can help you to resolve authentication issue
given().relaxedHTTPSValidation().auth().preemptive().basic("username", "token(in base 64 encryption")

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文