我收到错误 XMLHttpRequest无法加载“http://apiurl/signup”预检的响应包含无效的HTTP状态代码401 和选项401未经授权
服务器端和浏览器中启用了CORS 。
我是 Angular 2
的新手Http服务代码
signup(form : any)
{
const body = JSON.stringify(form);
console.log("HTTP",body);
const headers = new Headers({ 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
,'Authorization':'Basic <key>'
});
let options = new RequestOptions({headers : headers});
return this.http.post('http://--/signup',body,options).map((data:Response) => data.json())._catch(this.handleError).subscribe(
err => this.logError(err),
() =>console.log('Authentification Complete')
);
}
logError(err) {
console.error('There was an error: ' + err);}