2017-08-01 153 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; 
       });