【问题标题】:How to pass AccessToken key in Header in Rest Assured如何在 Rest Assured 的 Header 中传递 AccessToken 密钥
【发布时间】:2020-01-09 06:01:24
【问题描述】:

我的 API 使用 accesstoken 作为 Header 键和 Rest Assured 中的值

    Response response = httpRequest.request(Method.POST);
    //4. get the response body:
    String responseBody = response.getBody().asString();
    httpRequest.headers("accesstoken", "pbnQiOiIxMjM0NSJ9.");
    System.out.println("Response Body is: "+ responseBody);
    //validate city name or validate the key or value
    //Assert.assertEquals(responseBody.contains(city), true);


    //5. get the status code and validate it:
    int statusCode = response.getStatusCode();
    System.out.println("the status code is: "+ statusCode);

    Assert.assertEquals(statusCode, TestUtil.RESPONSE_CODE_200);

当我运行 Rest Assured 代码时,错误消息为 400。

【问题讨论】:

    标签: json rest-assured rest-assured-jsonpath


    【解决方案1】:

    我看到您正在执行 POST 请求。 400 错误消息意味着它是一个错误的请求。因此,请检查您是否发送了正文。如果您正在发送,请检查

    1. 您正在发送和预期的内容类型。是 application/json 还是 application/xml
    2. 输入 json 包含所有必要的字段和有效值

    【讨论】:

      猜你喜欢
      • 2023-03-14
      • 2012-03-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-20
      • 2012-01-23
      • 1970-01-01
      相关资源
      最近更新 更多