cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

CORS error while connecting Thingworx REST API to HTTP request- JavaScript XHR Vue.JS

Visitor

CORS error while connecting Thingworx REST API to HTTP request- JavaScript XHR Vue.JS

I have already configure my Tomcat serve for CORS still i am not able to access my api and i am getting " Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource."  

When i am trying to access the API using Postman i am getting 403 error.

For reference please check attached images. 

 

8 REPLIES 8

Re: CORS error while connecting Thingworx REST API to HTTP request- JavaScript XHR Vue.JS

Hi @shubhamm.

 

Have you made any changes to filter for CORS based on any documentation PTC provides?  If so, please provide specifics on the changes that were made.

 

What versions of Tomcat/ThingWorx are you running?

 

Here is an article that may help depending on the ThingWorx version you're running.

 

Regards.

 

--Sharon

Re: CORS error while connecting Thingworx REST API to HTTP request- JavaScript XHR Vue.JS

Tomcat 8.5.32

Thinworx 8.3

Re: CORS error while connecting Thingworx REST API to HTTP request- JavaScript XHR Vue.JS

Hi @shubhamm.

 

Have you made any changes to filter for CORS based on any documentation PTC provides?  If so, please provide specifics on the changes.

 

Was the article I provided helpful?

 

Regards.

 

--Sharon

Re: CORS error while connecting Thingworx REST API to HTTP request- JavaScript XHR Vue.JS

<filter>
<filter-name>CorsFilter</filter-name>
<filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
<init-param>
    <param-name>cors.allowed.origins</param-name>
    <param-value>*</param-value> 
</init-param>
<init-param>
    <param-name>cors.allowed.methods</param-name>
    <param-value>GET,POST,HEAD,OPTIONS,PUT</param-value>
</init-param>
<init-param>
    <param-name>cors.allowed.headers</param-name>
    <param-value>Content-Type,X-Requested-With,accept,Origin,Access-Control-Request-Method,Access-Control-Request-Headers,Access-Control-Allow-Origin,Access-Control-Allow-Host</param-value>
</init-param>
<init-param>
    <param-name>cors.exposed.headers</param-name>
    <param-value>Access-Control-Allow-Origin,Access-Control-Allow-Credentials,Access-Control-Allow-Host</param-value>
</init-param>
<init-param>
    <param-name>cors.support.credentials</param-name>
    <param-value>false</param-value>
</init-param>
<init-param>
    <param-name>cors.preflight.maxage</param-name>
    <param-value>10</param-value>
</init-param>
</filter>
<filter-mapping>
  <filter-name>CorsFilter</filter-name>
  <url-pattern>*</url-pattern>
</filter-mapping>​

This is my tomcat configuration and now i am able to access Thingworx API using Postman But again i am getting same error in my browser. 

Re: CORS error while connecting Thingworx REST API to HTTP request- JavaScript XHR Vue.JS

Re: CORS error while connecting Thingworx REST API to HTTP request- JavaScript XHR Vue.JS

Hi @shubhamm.

 

If one of the previous responses have helped with a solution, please mark the appropriate one as the Accepted Solution for the benefit of others with the same questions.

 

Regards.

 

--Sharon

Re: CORS error while connecting Thingworx REST API to HTTP request- JavaScript XHR Vue.JS

Hi 

  I try all the solution but still it is not working.
  i am getting same error.

Re: CORS error while connecting Thingworx REST API to HTTP request- JavaScript XHR Vue.JS

Hi @shubhamm.

 

How are you passing the AppKey?  Are you seeing the same error when you try to access it via your browser?

 

This article may help.

 

Regards.

 

--Sharon