gpt4 book ai didi

javascript - 如何在 Angular API 请求的 header 中传递 x-api-key?

转载 作者:太空狗 更新时间:2023-10-29 19:33:44 24 4
gpt4 key购买 nike

<分区>

我正在尝试在 header 中发送 x-api-key header ,如下所示

服务.ts

import { Injectable } from '@angular/core';
import { Http, Headers, RequestOptions, Response } from '@angular/http';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map';

@Injectable()
export class InsuranceServiceService {

public token: string;
constructor(private http: Http) {
const currentUser = JSON.parse(localStorage.getItem('currentUser'));
this.token = currentUser && currentUser.token;
}

createAuthorizationHeader(headers: Headers) {
headers.append('Content-Type', 'application/json');
headers.append('x-api-key', `xxxxxxxxxxxxxxxxxxxx`);
}

sendOTP(data: object): Observable<Object[]> {
const header = new Headers();
this.createAuthorizationHeader(header);
return this.http.post('http://my-omain.com/', data,
{
headers: header
})
.map((response: Response) => response.json());
}

}

但是,我收到以下错误:

Request header field x-api-key is not allowed by Access-Control-Allow-Headers in preflight response.

如何解决这个问题?有没有其他方法可以传递 x-api-key

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com