我正在尝试向 Wikipedia API 发送获取请求。我正在从一个角度前端发送请求,所以我尝试使用 Heroku CORS Anywhere 端点来避免 CORS 问题。出于某种原因,我仍然收到 503 响应,说请求的资源上没有 access-control-allow-origin 标头。知道为什么会发生这种情况/我还能尝试什么?
我的代码:
import { Injectable } from '@angular/core';
import { Http, Response, } from '@angular/http';
import { Observable } from 'rxjs/Rx';
@Injectable()
export class RestService {
API_URL: string = 'https://cors-anywhere.herokuapp.com/https://en.wikipedia.org/wiki/';
constructor(private http: Http) { }
public getRandomArticle() : Observable<any> {
return this.http.get(`${this.API_URL}Special:Random`)
.map((res: Response) => res.json())
.catch((err: any) => Observable.throw(err || 'server error'));
}
}