英文:
Getting 401 response code in rest assured tests
问题
我正在尝试修复我的Rest Assured测试,因为在我添加以下依赖后:
<dependency>
<groupId>de.ruedigermoeller</groupId>
<artifactId>fst</artifactId>
<version>3.0.4-jdk17</version>
</dependency>
现在在每个测试中都出现以下错误:
java.lang.AssertionError:
Expected :200
Actual :401
我正在使用以下依赖:
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>5.1.1</version>
<scope>test</scope>
</dependency>
我传递了所需的每个标头,包括使用用户名和密码编码的授权标头。此标头如下:
new Header("Authorization", "Basic XXXXYYYYXXSDSDDS=");
我将非常感谢任何帮助。谢谢。
英文:
Im trying to fix my rest assured test, because after i added
<dependency>
<groupId>de.ruedigermoeller</groupId>
<artifactId>fst</artifactId>
<version>3.0.4-jdk17</version>
</dependency>
And now in every single test i get:
> java.lang.AssertionError:
Expected :200
Actual :401
Im using:
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>5.1.1</version>
<scope>test</scope>
</dependency>
Im passing every header needed including Authorization header with username and password encoded. This header is like this:
new Header("Authorization", "Basic XXXXYYYYXXSDSDDS=");
I will be grateful for any help. Thanks.
答案1
得分: 0
似乎有某些内容覆盖了您的标头。
您可以在 RestAssured 调用中添加 log().all(),以便查看请求标头中是否包含授权标头。
这是解决问题的第一步。
或者,您可以使用以下代码来强制使用预先授权的基本身份验证:
given().auth()
.preemptive()
.basic("user1", "user1Pass")
英文:
It looks like something is overriding your headers.
Can you add log().all() to the RestAssured calls so that you can see if you have the Authorization header as part of the request headers?
Thats the first step to solve the issue.
Alternatively you can use this for forcing preemtive basic auth.
given().auth()
.preemptive()
.basic("user1", "user1Pass")
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论