2

I am just trying to use mocky.io from my http://localhost:8080

But getting this error:

XMLHttpRequest cannot load http://www.mocky.io/v2/5715f13a1100004d1187d9e1. 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.

My request looking like that:

let headers = new Headers();
  headers.append('Content-Type', 'application/json');
  headers.append('Access-Control-Allow-Origin', '*');
  this.people = http.get('http://www.mocky.io/v2/5715f13a1100004d1187d9e1', { headers: headers })
    .map(response => response.json());
0

2 Answers 2

2

Actually you should setup the header Access-Control-Allow-Origin in mocky.io. Just click on "Switch to Advanced mode" and you will see a "custom headers" input. Add Access-Control-Allow-Origin and put * as its value. Then create your mocky.io url. It should work now.

Sign up to request clarification or add additional context in comments.

Comments

0

It is looks like you are trying to access to other domain. Maybe add this in the web.config?

<httpProtocol> <customHeaders> <add name="Access-Control-Allow-Origin" value="http://localhost" />   </customHeaders> </httpProtocol>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.