我必须在标题中发送授权令牌并通过post调用从服务器获取数据,它会抛出错误。在标头中发送属性以呈现响应的正确方法是什么?
import {Injectable} from '@angular/core';
import {HttpClient} from '@angular/common/http';
import 'rxjs/add/operator/map';
@Injectable()
export class SearchService {
constructor(private http: HttpClient) {}
getSearch(searchObj: {}) {
const config = {
headers: {
'Authorization': 'Basic bTA5NDRpb25idXMuYXTVNAMjAxNw==',
'Content-Type': 'text/plain'
},
data: searchObj
};
console.log("searchObj", searchObj)
return this.http.post('http://service/getHistoricEvents', JSON.stringify(config))
//.map(res => res.json());
.map(res => console.log(res));
}
}
ERROR
Failed to load http://service/getHistoricEvents: Response for preflight is invalid (redirect)
core.js:1350 ERROR HttpErrorResponse {headers: HttpHeaders, status: 0, statusText: "Unknown Error", url: null, ok: false, …}