Service Virtualization

Expand all | Collapse all

Cross-Origin Request Blocked - Reason: CORS header ‘Access-Control-Allow-Origin’ missing

  • 1.  Cross-Origin Request Blocked - Reason: CORS header ‘Access-Control-Allow-Origin’ missing

    Posted Jul 03, 2017 08:07 AM

    We are trying to virtualize one REST API which is hosted on one of our server. We are using DevTest 10.1 workstation for this activity.

     

    We are successfully able to virtualize this API and able to get JSON response directly into the browser. However, when we try to use this virtualize image in a client application (in this case Angular JS) I am getting below error message.

     

    Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://10.20.30.40:8050/api/employee/GetAllEmployee. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).

     

    Although client application is giving correct response with the real service.

     

    Is there any specific setting on DevTest to fix this issue?



  • 2.  Re: Cross-Origin Request Blocked - Reason: CORS header ‘Access-Control-Allow-Origin’ missing

    Posted Jul 03, 2017 09:47 AM

    Did you build the service by recording the real application or from R/R Pairs?

     

    Do the responses in your VSI contain proper CORS response Meta Data header information (i.e., Access-Control-Allow-Origin, Access-Control-Allow-Credentials, etc.)?

     

    My limited understanding is that cross-domain support, in your example, means that the client-side application (AngularJ) is expecting HTTP response meta data for specific key/value pairs. 

     

    I have seen a different case where CORS (running in AngularJ) blocked the application from making a call to the server. We were researching the possibility of disabling CORS in the development environment to see if we could get around the issue. The other option we were exploring was to host the virtual services locally. 

     

    I wonder if SV as Code would make it easier as this option places the components local so no cross-domain interaction is required.  Welcome CodeSV  



  • 3.  Re: Cross-Origin Request Blocked - Reason: CORS header ‘Access-Control-Allow-Origin’ missing

    Posted Jul 13, 2017 12:15 PM

    Faheem,

     

    Did Joel's recommendations help you out with this issue?