有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

javascript错误:飞行前响应的HTTP状态代码401无效

我收到的错误是,XMLHttpRequest无法加载“http://apiurl/signup”响应,因为飞行前的HTTP状态代码401无效选项401未经授权

CORS服务器端和浏览器中启用

我是新来的Angular 2

form to be sent to the server consoleResponse

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) 个答案