0

I am trying to request whole html page using HttpClient module. This is my code:

this.http.get('http://google.com')
  .subscribe( data => {
    console.log(data);
  });

This is what I see in chrome network tab enter image description here This is the error that I get. enter image description here How can I do it properly?

Pitirus
  • 117
  • 1
  • 13
  • Why are you trying to request another web page from the client side using the `HttpClient`? – jonrsharpe Oct 19 '17 at 09:40
  • Or [google the error message](https://www.google.com/search?q=stackoverflow+failed+to+load+has+been+blocked+by+CORS+policy+no+access+control+allow+origin+header&oq=stackoverflow+failed+to+load+has+been+blocked+by+CORS+policy+no+access+control+allow+origin+header&gs_l=psy-ab.3...12292.29428.0.29663.45.45.0.0.0.0.183.4446.30j14.44.0....0...1.1.64.psy-ab..1.6.590...33i160k1j33i21k1.0.w6E21b_YoSU), they are there for a reason (to tell you what went wrong so you can try to fix it). – Igor Oct 19 '17 at 09:43
  • @jonrsharpe because it contains data that I need to display and doing it in server would introduce unnecessary overflow. – Pitirus Oct 19 '17 at 10:44

1 Answers1

0

Try using .jsonp() instead of .get(), it should prevent this (pretty common) CORS issue.

Milan Velebit
  • 1,933
  • 2
  • 15
  • 32
  • Would you be able to provide an example of this? I am not able to make it work myself. – Pitirus Oct 19 '17 at 10:46
  • See [this](https://stackoverflow.com/questions/29547003/angularjs-no-access-control-allow-origin-header-is-present-on-the-requested-r) – Milan Velebit Oct 19 '17 at 10:48