首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Swagger用户界面在响应体中返回“无内容”,响应代码0

Swagger用户界面在响应体中返回“无内容”,响应代码0
EN

Stack Overflow用户
提问于 2016-10-20 07:19:54
回答 2查看 12.3K关注 0票数 2

我是Swagger UI的新成员。我在Json中使用swagger。当响应也是时,Json。当单击尝试出时,我看到一个正确的请求URL,但是Swagger UI响应体中返回"no content"响应代码E 215 0

提到 API的URL并不是可以公开访问的,但是承载Swagger 的站点与承载的站点位于同一个网络中。

我看到了this堆栈溢出问题,但没有找到解决方案。

我的Swagger.Json文件:

代码语言:javascript
复制
{
    "swagger": "2.0",
    "info": {
        "version": "1.0.0",
        "title": "Swagger for Rest API",
        "description": "A sample API that uses a application as an example to demonstrate features in the swagger-2.0 specification",
        "termsOfService": "http://helloreverb.com/terms/",
        "contact": {
            "name": "Swagger API team",
            "email": "abc@gmail.com",
            "url": "http://xxxx.com"
        },
        "license": {
            "name": "MIT",
            "url": "http://opensource.org/licenses/MIT"
        }
    },
    "host": "localhost:85xx",
    "basePath": "/v1",
    "schemes": [
        "http"
    ],
    "consumes": [
        "application/json"
    ],
    "produces": [
        "application/json"
    ],
    "paths": {
        "/test/{username}/{albumname}/{imagename}": {
            "get": {
                "description": "Returns all images from the system that the user has access to",
                "operationId": "findface",
                "produces": [
                    "application/json",
                    "application/xml"
                ],
                "parameters": [
                    {
                        "name": "username",
                        "in": "path",
                        "description": "tags to filter by",
                        "required": true,
                        "type": "string"
                    },
                    {
                        "name": "albumname",
                        "in": "path",
                        "description": "maximum number of results to return",
                        "required": true,
                        "type": "string"
                    },
                    {
                        "name": "imagename",
                        "in": "path",
                        "description": "maximum number of results to return",
                        "required": true,
                        "type": "string"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "array",
                            "items": {
                                "$ref": "#/definitions/test1"
                            }
                        }
                    },
                    "default": {
                        "description": "unexpected error",
                        "schema": {
                            "$ref": "#/definitions/errorModel"
                        }
                    }
                }
            }
        }
    },
    "definitions": {
        "test1": {
            "type": "object",
            "required": [
                "id",
                "name"
            ],
            "properties": {
                "id": {
                    "type": "integer",
                    "format": "int64"
                },
                "name": {
                    "type": "string"
                },
                "tag": {
                    "type": "string"
                }
            }
        },
        "errorModel": {
            "type": "object",
            "required": [
                "code",
                "message"
            ],
            "properties": {
                "code": {
                    "type": "integer",
                    "format": "int32"
                },
                "message": {
                    "type": "string"
                }
            }
        }
    }
}

请任何一个人帮忙。提前谢谢。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-09-05 03:54:46

这应该是CORS的问题。您应该将Access-Control-Allow-Origin: *添加到响应头中。

请参阅:https://github.com/swagger-api/swagger-ui/blob/master/README.md#cors-support

票数 4
EN

Stack Overflow用户

发布于 2021-11-28 11:06:01

这应该是CORS的问题。您应该在响应头中添加访问控制-允许-原产地:*。

在启动类中使用此代码

//全球cors政策

代码语言:javascript
复制
 app.UseCors(x => x
            .AllowAnyOrigin()
            .AllowAnyMethod()
            .AllowAnyHeader());
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40147912

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档