Angular 角度5-获取错误为“否';访问控制允许原点';请求的资源上存在标头`

Angular 角度5-获取错误为“否';访问控制允许原点';请求的资源上存在标头`,angular,cors,Angular,Cors,我正在尝试将一个文件(上载的文件)发布到备份。获取此错误 Failed to load http://52.7.92.114:8080/cms-m2ts/rest/DocumentTagService/uploadFile: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested reso

我正在尝试将一个文件(上载的文件)发布到备份。获取此错误

Failed to load http://52.7.92.114:8080/cms-m2ts/rest/DocumentTagService/uploadFile: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access.
怎么想出这个?这里是我的服务:请纠正我哪里错了。但是上述内容在《邮递员》中没有任何问题

import { Injectable } from '@angular/core';
import { Http, Headers, RequestOptions } from '@angular/http';

import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map';


@Injectable()
export class DocUploadService {

    baseUrl: string = 'http://52.7.92.114:8080/cms-m2ts/rest/DocumentTagService';

    constructor(private http:Http) { }

    uploadDocument(file:File):Observable<File>{

        const headers = new Headers();
        headers.append('Content-Type', 'application/json');
        let options = new RequestOptions({ headers: headers, body:{"tagCount" : 5 } });

        const url = `${this.baseUrl}/uploadFile`;
        return this.http.post(url, file, options ).map(response => response.json())
    }

}
从'@angular/core'导入{Injectable};
从'@angular/Http'导入{Http,Headers,RequestOptions};
从“rxjs/Observable”导入{Observable};
导入'rxjs/add/operator/map';
@可注射()
导出类DocUploadService{
baseUrl:string='1〕http://52.7.92.114:8080/cms-m2ts/rest/DocumentTagService';
构造函数(私有http:http){}
上载文档(文件:file):可观察{
常量头=新头();
headers.append('Content-Type','application/json');
let options=newrequestoptions({headers:headers,body:{“tagCount”:5}});
常量url=`${this.baseUrl}/uploadFile`;
返回此.http.post(url、文件、选项).map(response=>response.json())
}
}

如果您发布文件的服务器在您的控制之下,请执行以下操作:-

  • 在同一资源上添加选项操作,并使用客户端IP或*提供Access Control Allow Origin标头以允许所有。 例如,如果是ASP.NET MVC应用程序,请使用Microsoft.ASPNET.CORS NuGet包,并在global.asax中应用EnableCors设置。其他环境将有自己的设置方式

如果没有,那么您需要让所有者为您设置

邮递员不验证CORS邮件头。请参见侧栏中的无数重复-->这不是角度问题。请使用后端的标签并重新表述您的问题。如果您不知道自己的错误是什么,请先进行谷歌搜索。您使用哪种语言作为后端?请解释否决投票的原因?