Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is there "no response from server" in Swagger UI?

Tags:

swagger-ui

My API calls work correctly in Postman. But when I send requests from Swagger UI, it shows "no response from server" for all requests:

Response Body
no content

Response Code
0

Response Headers

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

Swagger UI - no response from server

What can the problem be and how to fix it?

The browser console shows these errors:

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

like image 251
Andranik Avatar asked Aug 01 '17 13:08

Andranik


1 Answers

net::ERR_CONNECTION_REFUSED sounds like you need to enable CORS on your localhost, so that it sends the Access-Control-Allow-Origin: * header in responses. How you do this depends on the server you use. More info here:

https://enable-cors.org/server.html

https://github.com/swagger-api/swagger-ui/#cors-support

You may also need to allow OPTIONS pre-flight requests.

like image 103
Helen Avatar answered Oct 04 '22 23:10

Helen