I'm trying to get data through HTTP get request but I get the CORS error. I suppose the error is due to I don't use an "official" API. However, I am really curious whether it is possible to do web query of specific websites such as google or job-search website without using API via angular.
You can see my code as follows:
import { HttpClient, HttpHeaders } from "@angular/common/http";
import { Component } from "@angular/core";
@Component({
selector: "app-root",
templateUrl: "./app.component.html",
styleUrls: ["./app.component.scss"],
})
export class AppComponent {
title = "job-search";
url = "http://de.indeed.com/Jobs?as_and=Sprachlehrer";
constructor(private _http: HttpClient) {}
//"http://de.indeed.com/Jobs?as_and=Lehrer"
ngOnInit() {
let headersOpt = new HttpHeaders();
headersOpt.set("Content-Type", "application/json");
headersOpt.set("Access-Control-Allow-Origin", "*");
this._http
.get(this.url, {
headers: headersOpt,
})
.subscribe((res) => {
console.log(res);
});
}
}
I don't have a "real" HTML file here because I just want to get the query result.
Thank you for your solution.
Best regards I
Aucun commentaire:
Enregistrer un commentaire