Php 飞行响应中的访问控制允许标头不允许请求标头字段内容类型

Php 飞行响应中的访问控制允许标头不允许请求标头字段内容类型,php,angular,laravel,laravel-5,cors,Php,Angular,Laravel,Laravel 5,Cors,我正在用Laravel(RESTfulAPI)开发Angular4应用程序。我已经和邮递员一起测试了API。它工作正常,但当我从Angular 4调用API时,我得到以下错误: 从'@angular/core'导入{Injectable}; 从'@angular/Http'导入{Headers,Http}; 从“../models/User”导入{User}; 导入“rxjs/add/operator/toPromise”; @可注射() 导出类身份验证服务{ 私有基URL:string='1

我正在用Laravel(RESTfulAPI)开发Angular4应用程序。我已经和邮递员一起测试了API。它工作正常,但当我从Angular 4调用API时,我得到以下错误:

从'@angular/core'导入{Injectable};
从'@angular/Http'导入{Headers,Http};
从“../models/User”导入{User};
导入“rxjs/add/operator/toPromise”;
@可注射()
导出类身份验证服务{
私有基URL:string='1!'http://localhost/fmfb_hr/public/api';
私有头:头=新头({'Content-Type':'application/json'});
构造函数(私有http:http){}
登录(用户):承诺{
让url:string=`${this.BASE_url}/login`;
返回this.http.post(url,用户,{headers:this.headers}).toPromise();
}
}

将这三行添加到服务器上以优化服务器。如果使用Apache作为web服务器,请将以下行添加到
.htaccess
文件中:

Header set Access-Control-Allow-Origin "*"
Header set Access-Control-Allow-Methods "GET,PUT,POST,DELETE"
Header set Access-Control-Allow-Headers "Content-Type, Authorization"

将这三行添加到CORSify服务器上。如果使用Apache作为web服务器,请将以下行添加到
.htaccess
文件中:

Header set Access-Control-Allow-Origin "*"
Header set Access-Control-Allow-Methods "GET,PUT,POST,DELETE"
Header set Access-Control-Allow-Headers "Content-Type, Authorization"

试试这段代码,在一个请求中添加两个头,我希望这能起作用

import { Injectable } from '@angular/core';
import { Headers, Http } from '@angular/http';
import { User } from '../models/user';
import 'rxjs/add/operator/toPromise';

@Injectable()
export class AuthService {
    private BASE_URL: string = 'http://localhost/fmfb_hr/public/api';
    private headers: Headers = new Headers({});
    constructor(private http: Http) {}
    login(user): Promise<any> {
        let url: string = `${this.BASE_URL}/login`;
        this.headers.append('Content-Type','application/x-www-form-urlencoded');
        this.headers.append('Content-Type','application/json');
        return this.http.post(url, user, {headers: this.headers}).toPromise();
    }
}
从'@angular/core'导入{Injectable};
从'@angular/Http'导入{Headers,Http};
从“../models/User”导入{User};
导入“rxjs/add/operator/toPromise”;
@可注射()
导出类身份验证服务{
私有基URL:string='1!'http://localhost/fmfb_hr/public/api';
私有头:头=新头({});
构造函数(私有http:http){}
登录(用户):承诺{
让url:string=`${this.BASE_url}/login`;
this.headers.append('Content-Type','application/x-www-form-urlencoded');
append('Content-Type','application/json');
返回this.http.post(url,用户,{headers:this.headers}).toPromise();
}
}

试试这段代码,在一个请求中添加两个头,我希望这能奏效

import { Injectable } from '@angular/core';
import { Headers, Http } from '@angular/http';
import { User } from '../models/user';
import 'rxjs/add/operator/toPromise';

@Injectable()
export class AuthService {
    private BASE_URL: string = 'http://localhost/fmfb_hr/public/api';
    private headers: Headers = new Headers({});
    constructor(private http: Http) {}
    login(user): Promise<any> {
        let url: string = `${this.BASE_URL}/login`;
        this.headers.append('Content-Type','application/x-www-form-urlencoded');
        this.headers.append('Content-Type','application/json');
        return this.http.post(url, user, {headers: this.headers}).toPromise();
    }
}
从'@angular/core'导入{Injectable};
从'@angular/Http'导入{Headers,Http};
从“../models/User”导入{User};
导入“rxjs/add/operator/toPromise”;
@可注射()
导出类身份验证服务{
私有基URL:string='1!'http://localhost/fmfb_hr/public/api';
私有头:头=新头({});
构造函数(私有http:http){}
登录(用户):承诺{
让url:string=`${this.BASE_url}/login`;
this.headers.append('Content-Type','application/x-www-form-urlencoded');
append('Content-Type','application/json');
返回this.http.post(url,用户,{headers:this.headers}).toPromise();
}
}

这可能是CORS的问题。如何使用LARAVEL解决它创建CORS中间件。有关更多详细信息,请参阅。我已经阅读了这篇文章并尝试了,但它不起作用。这可能是CORS问题。如何使用LARAVEL解决它创建CORS中间件。请参阅以了解更多详细信息。我已经阅读了这篇文章并尝试了一下,但它不起作用