错误:预检的响应具有无效的HTTP状态代码401

时间:2017-03-24 07:32:56

标签: javascript java angular typescript ionic2

我收到错误 XMLHttpRequest无法加载“http://apiurl/signup”预检的响应包含无效的HTTP状态代码401 选项401未经授权

服务器端浏览器中启用了

CORS

我是 Angular 2

的新手

form to be sent to the server console Response

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);}

0 个答案:

没有答案