cors-anywhere.herokuapp.com无法正常运行(503).我还能尝试什么? [英] cors-anywhere.herokuapp.com not working (503). What else can I try?
问题描述
我正在尝试将获取请求发送到Wikipedia API.我正在从一个有角度的前端发送请求,因此我尝试使用Heroku CORS Anywhere端点来避免CORS问题.出于某种原因,我仍然收到503响应,表示请求的资源上不存在access-control-allow-origin头.知道为什么会发生这种情况/我还能尝试什么?
I am trying to send a get request to the Wikipedia API. I am sending the request form a angular frontend so i'm trying to use the Heroku CORS Anywhere endpoint to avoid CORS issues. For some reason, I'm still getting a 503 response saying no access-control-allow-origin header is present on the requested resource. Any idea why this would happen/what else I can try?
我的代码:
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'));
}
}
推荐答案
您只需花费2-3分钟,即可使用5条命令将 CORS Anywhere 服务器部署到Heroku中:
You can deploy a CORS Anywhere server to Heroku in literally just 2-3 minutes, with 5 commands:
git clone https://github.com/Rob--W/cors-anywhere.git
cd cors-anywhere/
npm install
heroku create
git push heroku master
运行这些命令后,您将最终运行在 https://cryptic-headland-94862.herokuapp.com/.因此,不要在请求URL前面加上https://cors-anywhere.herokuapp.com
前缀,而是在您自己的代理URL前面加上前缀.
After running those commands, you’ll end up with your own CORS Anywhere proxy running at, e.g., https://cryptic-headland-94862.herokuapp.com/. So then instead of prefixing your request URL with https://cors-anywhere.herokuapp.com
, prefix it instead with your own proxy’s URL.
这篇关于cors-anywhere.herokuapp.com无法正常运行(503).我还能尝试什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!