如何在这种情况下使用基本身份验证并放心
我正在尝试将身份验证与重新确定。 这是我的代码不起作用:
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请放心,除非服务器挑战,否则使用基本身份验证时不会发送凭据。如果服务器没有挑战,则不会发送。如果是这种情况,您可以使用先发制的基本身份验证:
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:
我希望以下代码可以帮助您解决身份验证问题
给定()。selieedhttpsvalidation()。auth()。
I hope below code can help you to resolve authentication issue
given().relaxedHTTPSValidation().auth().preemptive().basic("username", "token(in base 64 encryption")