spring-boot - Swagger 类型错误 : Failed to execute 'fetch' on 'Window' : Request with GET/HEAD method cannot have body

标签 spring-boot swagger swagger-ui swagger-2.0

我已将 Swagger 添加到我的 Spring Boot 2 应用程序中:

这是我的 Swagger 配置:

@Configuration
@EnableSwagger2
public class SwaggerConfig {

    @Bean
    public Docket api() {
        // @formatter:off
        return new Docket(DocumentationType.SWAGGER_2)  
                .select()                                  
                .apis(RequestHandlerSelectors.any())              
                .paths(PathSelectors.any())                          
                .build();
        // @formatter:on
    }
}

这是 Maven 依赖项:
<!-- Swagger2 -->
<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger2</artifactId>
    <version>2.8.0</version>
</dependency>
<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger-ui</artifactId>
    <version>2.8.0</version>
</dependency>

当我尝试调用例如 http://localhost:8080/api/actuator/auditevents它失败并出现以下错误:
TypeError: Failed to execute 'fetch' on 'Window': Request with GET/HEAD method cannot have body.

enter image description here

我做错了什么以及如何解决?

最佳答案

错误消息实际上说明了问题所在。您使用 curl 发布数据在尝试使用 GET 时使用 -d 选项。

如果你使用 -d 选项 curl 会做 POST .
如果你使用 -X GET 选项 curl 会做 GET .

HTTP GET 方法用于请求指定资源的表示。使用 GET 的请求应该只检索数据,因此不能有正文。

更多信息 GET vs POST

关于spring-boot - Swagger 类型错误 : Failed to execute 'fetch' on 'Window' : Request with GET/HEAD method cannot have body,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48749252/

相关文章:

c# - 在 IIS 中运行时出现 Swashbuckle 错误 - 404( 'swagger.json')

swagger - 任何 : {$ref} in swagger JSON schema definition

c# - 如何将键值对传递给 ASP.NET Core WebApi 中的 HttpGet?

java - 如何对 Springboot API 进行端到端测试?

javascript - 如何记录现有的 nodejs API?

java - Spring Boot 2.0 Gradle 在 IntelliJ 中运行和测试

c# - 来自枚举的 Swagger 预定义返回类型值

spring-boot - 更新 Swagger code-gen 生成的代码

mysql - Spring Boot版本升级-mysql错误

maven - 使用 IntelliJ 部署启用嵌入式 tomcat 的 spring-boot 应用程序