如何在头文件中传递授权令牌?

时间:2017-09-17 13:35:44

标签: java rest

尝试使用Restured

自动执行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());
}

1 个答案:

答案 0 :(得分:11)

添加授权标题。

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

有关详细信息,请参阅here.

相关问题