如何设置授权标题/重置现有标题?

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

我正在使用Rest-Assured进行api测试,我的场景是1.Upload 2.GetContent

我尝试添加

RestAssured.given().auth().basic(userName, password)

它没有验证我并设置标题,我得到未经验证的错误。

我也尝试过添加

RestAssured.given().header("authorization", ConfigHelper.getString(user));

得到同样的错误。对我有用的唯一的事情是,

getRequest().header("authorization", ConfigHelper.getString(user));

但是我使用getRequest的问题是我无法使用方案1和2重置请求,所以如果我在scenario1中设置了授权,当我尝试在方案2中进行身份验证时,它会在Header中复制身份验证并给我一个

错误的请求

错误。有没有办法重置标题?

api rest-assured web-api-testing
1个回答
0
投票
this.setRequest(RestAssured.given().auth().preemptive().basic(userName, password)
                .header("Content-type", "multipart/form-data")
                .multiPart("file", new File(pathToFile, "application/json"));
© www.soinside.com 2019 - 2024. All rights reserved.