【问题标题】:I am getting "java.util.zip.ZipException: unknown compression method" in my restassured code我在放心的代码中收到“java.util.zip.ZipException:未知压缩方法”
【发布时间】:2023-03-15 05:28:01
【问题描述】:

我收到此错误“java.util.zip.ZipException:未知压缩方法”,但我正在处理 API 放心。会不会和 pom.xml 中的依赖有关?

我用谷歌搜索了这个问题,发现它是关于 zip 文件的,但正如你所见,没有 zip 编码。

这是我的代码和 pom.xml:

@Test
public void trelloCallTest() {
    String key = "mykey";
    String token = "mytoken";

    Response response = given()
        .spec(new RequestSpecBuilder().setBaseUri("https://api.trello.com/1").build())
        .contentType(ContentType.JSON)
        .log().all()
        .when()
        .queryParams("key", key,
            "token",
            token,
            "name", "myname")
        .post("/boards/");

    String jsonString = response.asString();
    System.out.println(jsonString);

    response.then().statusCode(200);
}

这是我的 pom.xml:

<dependencies>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-engine</artifactId>
        <version>5.5.2</version>
    </dependency>
    <dependency>
        <groupId>io.rest-assured</groupId>
        <artifactId>rest-assured</artifactId>
        <version>4.3.0</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/com.googlecode.json-simple/json- 
             simple -->
    <dependency>
        <groupId>com.googlecode.json-simple</groupId>
        <artifactId>json-simple</artifactId>
        <version>1.1.1</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>2.8.6</version>
    </dependency>
    <dependency>
        <groupId>org.json</groupId>
        <artifactId>json</artifactId>
        <version>20210307</version>
    </dependency>
    <dependency>
        <groupId>javax.xml.bind</groupId>
        <artifactId>jaxb-api</artifactId>
        <version>2.3.0</version>
    </dependency>
    <dependency>
        <groupId>org.codehaus.groovy</groupId>
        <artifactId>groovy-all</artifactId>
        <version>2.4.5</version>
    </dependency>
</dependencies>

【问题讨论】:

标签: java api rest-assured rest-assured-jsonpath


【解决方案1】:

从您的代码中,您有post("/boards/") - 我没有发现您尝试执行该https://developer.atlassian.com/cloud/trello/rest/api-group-boards/ 的方式支持发布请求您面临的问题可能与意外响应类型有关,例如它可能被压缩

【讨论】:

    【解决方案2】:

    您好,我编辑了这些行并工作了:

     Response response = given().spec(new RequestSpecBuilder().setBaseUri("https://api.trello.com/1").setContentType(ContentType.JSON)
                    .build())
                    .log().all()
                    .when()
                    .queryParams("key", key,
                           "token",
                                 token,
                                 "name", "myname")
                    .post("/boards/");
    

    【讨论】:

      猜你喜欢
      • 2012-03-29
      • 1970-01-01
      • 2023-03-11
      • 1970-01-01
      • 1970-01-01
      • 2021-02-04
      • 1970-01-01
      • 1970-01-01
      • 2015-10-28
      相关资源
      最近更新 更多