Java 如何在放心的标头中传递授权令牌?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/46264650/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 02:18:24  来源:igfitidea点击:

How to pass authorization token in header in Rest assured?

javarest

提问by Bharath S

Trying to automate api testing using Rest assured

尝试使用放心自动化 API 测试

@Test
public void Login() {
    Response resp = given().
            body("{\"phone_number\":\"2222222222\",\"\r\n" + 
                    "               + \" \"country_code\": \"+91\",\"\r\n" + 
                    "               + \" \"login_type\": 0}").
            when().
            contentType(ContentType.JSON).
            post("http://url/api/v1/login");

    System.out.println(resp.asString());
}

采纳答案by Nabin Bhandari

Add authorization header.

添加授权头。

Response resp = given().header("Authorization", "Bearer "+token).body(...

For more info, see here.

有关更多信息,请参阅此处。