Swagger TypeError:无法在“窗口"上执行“获取":使用 GET/HEAD 方法的请求不能有正文 [英] Swagger TypeError: Failed to execute 'fetch' on 'Window': Request with GET/HEAD method cannot have body
问题描述
我已将 Swagger 添加到我的 Spring Boot 2 应用程序中:
这是我的 Swagger 配置:
@Configuration@EnableSwagger2公共类 SwaggerConfig {@豆公共 Docket api() {//@格式化程序:关闭返回新的 Docket(DocumentationType.SWAGGER_2).select().apis(RequestHandlerSelectors.any()).paths(PathSelectors.any()).build();//@格式化程序:打开}}
这是Maven依赖:
<依赖><groupId>io.springfox</groupId><artifactId>springfox-swagger2</artifactId><version>2.8.0</version></依赖><依赖><groupId>io.springfox</groupId><artifactId>springfox-swagger-ui</artifactId><version>2.8.0</version></依赖>
当我尝试调用例如
我做错了什么以及如何解决?
错误消息实际上说明了问题所在.您在尝试时使用 -d 选项使用 curl 发布数据使用GET.
如果您使用 -d 选项 curl 将执行 POST.
如果您使用 -X GET 选项 curl 将执行 GET.
HTTP GET 方法用于请求指定资源的表示.使用 GET 的请求应该只检索数据,因此不能有正文.
的更多信息I have added Swagger to my Spring Boot 2 application:
This is my Swagger config:
@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
}
}
This is Maven dependency:
<!-- 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>
When I try to invoke for example http://localhost:8080/api/actuator/auditevents it fails with the following error:
TypeError: Failed to execute 'fetch' on 'Window': Request with GET/HEAD method cannot have body.
What am I doing wrong and how to fix it ?
The error message actually says what the problem is. You post data with curl using the -d option while trying to use GET.
If you use the -d option curl will do POST.
If you use -X GET option curl will do GET.
The HTTP GET method is for requesting a representation of the specified resource. Requests using GET should only retrieve data and hence cannot have body.
More info on GET vs POST
这篇关于Swagger TypeError:无法在“窗口"上执行“获取":使用 GET/HEAD 方法的请求不能有正文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!