package com.automation.tests;
import static io.restassured.RestAssured.*;
import org.json.JSONObject;
import io.restassured.response.Response;
import io.restassured.specification.RequestSpecification;
public class AspenTest {
public static void main(String[] args) {
JSONObject churnUsageBody = new JSONObject();
churnUsageBody.put("customer_id", "c096");
RequestSpecification sp = given().baseUri("http://192.168.180.12:4000/")
.header("Content-Type", "application/json")
.header("X-CSRFToken", "EZpbczzL5yiBHKT0fn2PcfPszp0IfHwPLn3pmXJYA8BX8bH6Gn6ILrlAJPSuX1uq")
.header("Authorization", "Token d2618176b9b9aed6dc0a9cb3a1ebfe1c4c8831ed999bdce4432e061aa56f672f")
.body(churnUsageBody.toString());
Response rs = sp.post("churn/app/usgscore");
System.out.println(rs.asPrettyString());
}
}
我尝试在添加授权令牌后运行 api,但收到以下错误,即使令牌是正确的,并且该 api 也在 postman 中工作。
{
"detail": "Authentication credentials were not provided."
}
为了调试这个问题,我有两个建议给你:
请检查 API 是否需要在实际令牌之前添加“Token”一词。某些 API 期望在实际令牌之前添加“Bearer”。 {.header("授权", "承载 d2618176b9b9aed6dc0a9cb3a1ebfe1c4c8831ed999bdce4432e061aa56f672f")}
通过启用日志记录 ( log().all()) 来记录您的请求,以便调试您的请求并验证标头和正文是否正确发送。 资源