I have fixed this issue by adding the CORSfilter in server side ( where
REST API is hosted)  web.xml .
 <filter>
   <filter-name>CorsFilter</filter-name>
   <filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
 </filter>
 <filter-mapping>
   <filter-name>CorsFilter</filter-name>
   <url-pattern>/*</url-pattern>
 </filter-mapping>

and adding
swaggerUi.api.clientAuthorizations.add("key", new
SwaggerClient.ApiKeyAuthorization("Access-Control-Request-Headers",
"X-Custom-Header", "header

in index.html of swagger ui package.

This will make swagger ui work in ie, chrome and mozilla firefox. and i got
the expected response.



On Mon, Nov 7, 2016 at 11:31 AM, Meera nyjen <[email protected]> wrote:

> Hi All,
>
> I am trying to test a rest api hosted in a different domain using swagger
> ui.
> This swagger ui is hosted in my local machine with Apache tomcat.
>
> Now, when i try to access a rest api hosted in a different machine using
> 'Try it out' button in swagger ui, it gives 'error": "no response from
> server"
>
> In chrome debug window, I can see this message "XMLHttpRequest cannot load
> http://XX.XX.XX.XX:83/MyRestAPI. Response to preflight request doesn't
> pass access control check: No 'Access-Control-Allow-Origin' header is
> present on the requested resource. Origin 'http://localhost:8080' is
> therefore not allowed access.
>
> In Network console, I am getting the expected response :200.
>
> I tried adding CORS filter in my Tomcat web.xml, but it does not work.
>
> Is there any way to add "Access-Control-Allow-Origin" in the request
> header ?
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to