2017-08-01 69 views
1

我的API调用在邮差中正常工作。但是,当我从扬鞭UI发送请求,它显示了所有的请求“服务器没有响应”:Swagger UI中为什么“服务器没有响应”?

Response Body
no content

Response Code
0

Response Headers

{ 
    "error": "no response from server" 
} 

Swagger UI - no response from server

什么可问题是,如何解决?

浏览器控制台显示这些错误:

Failed to load resource: net::ERR_CONNECTION_REFUSED

Uncaught TypeError: Cannot read property 'length' of undefined
   at showStatus (index.js:24)
   at showErrorStatus (index.js:24)
   at error (index.js:607) at spec-converter.js:533
   at Request.callback (index.js:24)
   at Request.crossDomainError (index.js:24)
   at XMLHttpRequest.xhr.onreadystatechange (index.js:24)

Swagger UI - console errors

+0

是您的服务器上启用CORS?浏览器控制台中是否有错误? – Helen

+0

是无法加载资源:净:: ERR_CONNECTION_REFUSED index.js:24遗漏的类型错误:在showStatus无法读取的不确定 财产 '长度'(index.js:24) 在showErrorStatus(index.js:24) 在误差(index.js:607) 在SPEC-converter.js:533 在Request.callback(index.js:24) 在Request.crossDomainError(index.js:24) 在XMLHttpRequest.xhr.onreadystatechange(索引.js文件:24) – Andranik

回答

2

由于串行器响应中的引用循环,Swagger返回0响应代码。

在获取串行器响应时忽略参考循环。

如果您正在使用的Web API,使用下面的代码

services.AddMvc() 
       .AddJsonOptions(opt => 
       { 
        opt.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore; 
       });