Search code examples
swagger-ui

Why is there "no response from server" in 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


Solution

  • 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.