预检请求不会通过访问控制

时间:2018-04-18 10:07:22

标签: javascript json cors angular5 zoho

我想将Zoho Desk API集成到我的角度应用程序中,当我调用GET时出现此错误 “无法加载https://desk.zoho.com/api/v1/tickets?include=contacts:对预检请求的响应未通过访问控制检查:请求的资源上没有”Access-Control-Allow-Origin“标头。因此,”http://localhost:4200“原因是不允许访问。响应的HTTP状态代码为405“

我的Intercepter添加标题信息

import { Injectable } from '@angular/core';
import { HttpEvent, HttpInterceptor, HttpHandler, HttpRequest } from '@angular/common/http';
import { Observable } from 'rxjs/observable';
@Injectable()
export class ZohoAuthInterceptor implements HttpInterceptor {
  intercept (req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
    const authReq = req.clone({
        headers: req.headers.set('orgId', 'myorgId')
                            .set('Authorization', 'myAuth')
      });

    return next.handle(authReq);
  }
}

在我的componet.ts

  constructor(private http:HttpClient) {
    this.http.get('https://desk.zoho.com/api/v1/tickets?include=contacts').subscribe(data => {
      console.log(data);
    });
   }

0 个答案:

没有答案