【问题标题】:swagger-ui trying to download index.htmlswagger-ui 试图下载 index.html
【发布时间】:2018-02-03 19:48:07
【问题描述】:

当我在浏览器中导航到 index.html 页面而不是将其显示为 html 页面时,我遇到了一个问题。不知道是什么原因造成的。

我正在使用带有 Spring 的 Swagger 1.3.4。

弹簧配置:

@Configuration
public class SwaggerConfig {

@Bean
public BeanConfig beanConfig() {
    final BeanConfig beanConfig = new BeanConfig();
    beanConfig.setResourcePackage("com.example.rest.ws");
    beanConfig.setVersion("1.0");
    beanConfig.setBasePath("my-rest-services");
    beanConfig.setTitle("My API");
    beanConfig.setScan(true);
    return beanConfig;
}

}

然后我在浏览器中向以下内容发出请求:

https://example.com/my-rest-services/swagger-ui/index.html

它会尝试下载 index.html 文件。我检查了响应标头,它们如下:

 Accept-Ranges:bytes
 Age:2000
 Connection:Keep-Alive
 Content-Length:3467
 Content-Type:application/octet-stream
 Date:Fri, 24 Aug 2017 15:15:23 GMT
 Server:Apache-Coyote/1.1

为什么 Swagger 会返回八位字节流 Content-Type?

【问题讨论】:

    标签: spring swagger swagger-ui


    【解决方案1】:

    设置内容类型响应标头的是 Web 服务器。从您的响应标头看来,apache 是 Web 服务器。

    在 Apache 中,MIME 类型和文件扩展名之间的映射存储在配置文件 apache_home/conf/mime.types 中,其中 apache_home 是 Apache 在您的服务器上安装的路径。

    在文本编辑器中打开mime.types文件,检查html文件的映射是否存在,如下:

    文本/html html htm

    其中,text/html 是 mime 类型,html,htm 是文件扩展名。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-09-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-05
      • 2015-07-31
      • 2021-09-01
      相关资源
      最近更新 更多