我尝试从POSTMAN API正常工作,但无法通过我的放心代码

时间:2020-03-03 06:38:09

标签: rest automation rest-assured

得到的响应为“响应: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());

1 个答案:

答案 0 :(得分:0)

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

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