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());
Nick F
  • 9,781
  • 7
  • 75
  • 90
Sergino
  • 10,128
  • 30
  • 98
  • 159

2 Answers2

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.

R. Gregori
  • 56
  • 5
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>
The scion
  • 1,001
  • 9
  • 19