我正在尝试将文件(已上传的文件)发布到支持。得到这个错误。
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.
如何提出这个?这是我的角度服务:无论我错在哪里,请纠正我。但上述内容在postman
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())
}
}
答案 0 :(得分:-1)
如果您发布文件的服务器在您的控制范围内,请执行以下操作: -
如果没有,那么您需要请业主为您设置。