“跨源请求已阻止”。在Angular中使用HomeAway API

时间:2018-10-24 17:28:43

标签: angular api http cors

我正在尝试为HomeAway拥有的VRBO上列出的财产创建一个网站。他们有一个API,可让您查看媒体资源,评论等。我正在使用HomeAway API来随时获取更新的评论列表。

我已经使用Postman应用程序弄弄了API,并检索了我希望接收的数据,但是我没有在Angular项目上工作,该项目将检索该数据并显示出来。

import { Injectable } from '@angular/core';
import { Http, RequestOptions, Headers } from '@angular/http';
import { HttpHeaders } from '@angular/common/http';
import { Observable, throwError } from 'rxjs';
import { catchError, retry, map } from 'rxjs/operators';

@Injectable({
  providedIn: 'root'
})
export class VrboServiceService {
  private requestOptions = new RequestOptions({
    headers: new Headers({ 
      'Authorization': 'Bearer TOKENGOESHERESJLSJKLAKSADASA',
      "Access-Control-Allow-Headers": "Origin, X-Requested-With, Content-Type, Accept",
      'Access-Control-Allow-Origin': '*'
    }),
    withCredentials: true
  });


  private reviewsUrl = 'https://ws.homeaway.com/public/listing?id=v441437&q=REVIEWS';

  constructor(public http: Http) {
    console.log("Data Service Connected");
  }


  getReviews(){
    return this.http.get(this.reviewsUrl, this.requestOptions)
      .pipe(map(res => res.json()));


  }

这将返回错误:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://ws.homeaway.com/public/listing?id=v441437&q=REVIEWS. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).[Learn More]
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://ws.homeaway.com/public/listing?id=v441438&q=REVIEWS. (Reason: CORS request did not succeed).[Learn More]

我已经阅读了一些有关此问题的文章(并且几乎什么都不了解),但是这个特定的API不允许CORS的问题吗?如果我确实为我的网页有了域名(我打算这样做),是否可以解决?我该怎么办?

0 个答案:

没有答案