首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >“傲慢编辑器”:找不到错误服务器或发生错误

“傲慢编辑器”:找不到错误服务器或发生错误
EN

Stack Overflow用户
提问于 2016-10-18 07:49:32
回答 3查看 2.9K关注 0票数 4

我在Swagger工具上比较新。我试着用swagger编辑器测试我的Restfull应用程序。我使用基本身份验证来访问web服务。

Swagger -UI中,预览看起来是正确的,即内容类型:application/json和json在body.But中,当我从Swagger编辑器发送请求到服务器时,我得到了一个错误。

代码语言:javascript
复制
ERROR Server not found or an error occurred

My Swagger

代码语言:javascript
复制
{
    "swagger": "2.0",
    "info": {
        "version": "1.0.0",
        "title": "Swagger Petstore (Simple)",
        "description": "A sample API that uses a petstore 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://avfg.com"
        },
        "license": {
            "name": "MIT",
            "url": "http://opensource.org/licenses/MIT"
        }
    },
    "host": "127.0.0.1:8xxx",
    "basePath": "/v1",
    "schemes": [
        "http"
    ],
    "consumes": [
        "application/json"
    ],
    "produces": [
        "application/json"
    ],
    "paths": {
        "/facedetect/{username}/{albumname}/{imagename}": {
            "get": {
                "description": "Returns all pets from the system that the user has access to",
                "operationId": "findPets",
                "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": "pet response",
                        "schema": {
                            "type": "array",
                            "items": {
                                "$ref": "#/definitions/pet"
                            }
                        }
                    },
                    "default": {
                        "description": "unexpected error",
                        "schema": {
                            "$ref": "#/definitions/errorModel"
                        }
                    }
                }
            }
        }
    },
    "definitions": {
        "pet": {
            "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

回答 3

Stack Overflow用户

回答已采纳

发布于 2017-04-14 09:47:15

我找到解决办法了。

它的CORS问题。我的浏览器阻塞了cors请求。我安装了一个将Access-Control-Allow-Origin添加到传出请求的Chrome扩展

票数 1
EN

Stack Overflow用户

发布于 2016-12-05 19:15:35

确保您的服务器正在运行。

如果您安装了swagger,您可以

代码语言:javascript
复制
swagger project start
票数 1
EN

Stack Overflow用户

发布于 2018-08-09 21:07:11

我有个小问题

这是CORS,但是:

在nodeJS中,我设置了:

代码语言:javascript
复制
app.use(function(req, res, next) {
  res.header("Access-Control-Allow-Origin", "*");
  res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept, Authorization');
  res.header('Access-Control-Allow-Methods', 'GET, POST, PUT, UPDATE, DELETE, OPTIONS')
  res.header("Content-Type", "application/json");
  next();
});

但是,只有在请求未经授权(api-key)的情况下才有帮助。要使它发挥作用,我必须改变和使用:

代码语言:javascript
复制
const cors = require('cors');
app.use(cors());

希望能帮上忙

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40102506

复制
相关文章

相似问题

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