【问题标题】:I tried from POSTMAN API working fine but not from my Rest assured code我尝试从 POSTMAN API 工作正常,但不是从我的放心代码
【发布时间】:2020-03-03 06:38:09
【问题描述】:

获取响应为“响应:tcp_error:发生通信错误:“操作超时”
"

来自 POSTMAN/Curl

    curl -X POST \
  http://IP:PORT/{endpoint} \
  -H 'Accept: application/json' \
  -H 'Accept-Encoding: gzip, deflate' \
  -H 'Cache-Control: no-cache' \
  -H 'Connection: keep-alive' \
  -H 'Content-Length: 5' \
  -H 'Content-Type: application/json' \
  -H 'Host: IP:PORT' \
  -H 'Postman-Token: 053670e6-44d4-4d03-96bf-ab1178b02d06,ffad205d-320a-4cd0-a63d-1687873fbf1d' \
  -H 'User-Agent: PostmanRuntime/7.19.0' \
  -H 'appkey: ACTUAL APP KEY' \
  -H 'cache-control: no-cache' \
  -d '{

}'

上述 API 的可靠代码

RestAssured.baseURI = “http://IP”;
        RestAssured.port = port;
        RestAssured.useRelaxedHTTPSValidation();

        Response response = RestAssured.given()

                .header("Accept", "application/json")
                .header("Content-Type", "application/json")
                .header("appkey", “ACTUAL APPKEY”)
                .when()
                .get(“ENDPOINT”);

        System.out.println("Response: " + response.asString());

【问题讨论】:

  • 发布代码,你尝试了什么,向我们展示邮递员的请求。
  • Fenio,以 curl 形式更新了代码和邮递员请求详细信息

标签: rest automation rest-assured


【解决方案1】:

请放心尝试设置编码器配置。它会解决这个问题。

given().config(RestAssured.config().encoderConfig(encoderconfig.appendDefaultContentCharsetToContentTypeIfUndefined(false)));

【讨论】:

    猜你喜欢
    • 2017-07-07
    • 2016-11-27
    • 1970-01-01
    • 2021-11-24
    • 2021-03-28
    • 2022-06-13
    • 1970-01-01
    • 2014-04-23
    • 2021-05-18
    相关资源
    最近更新 更多