Angular 2 Token: Antwort für Preflight hat ungültigen HTTP-Statuscode 400
Ich habe eine Angular2 / TypeScript-Anwendung, in der i Visual Studio Code ausgeführt wird.
Eine API, die in VS 2015 ausgeführt wird. Dies ist das API-Projekt:http: //www.asp.net/web-api/overview/security/individual-accounts-in-web-ap
Ich kann die API verwenden und neue Benutzer erstellen. Beim Versuch, mich anzumelden (Token-Funktion verwenden), wird jedoch die folgende Fehlermeldung angezeigt:XMLHttpRequest kann nicht geladen werdenhttps: // localhost: 44305 / Token. Antwort für Preflight hat ungültigen HTTP-Statuscode 400
Der Header sieht folgendermaßen aus:
Request URL:https://localhost:44305/Token
Request Method:OPTIONS
Status Code:400
Remote Address:[::1]:44305
Response Headers
cache-control:no-cache
content-length:34
content-type:application/json;charset=UTF-8
date:Wed, 10 Aug 2016 19:12:57 GMT
expires:-1
pragma:no-cache
server:Microsoft-IIS/10.0
status:400
x-powered-by:ASP.NET
x-sourcefiles:=?UTF-8?B?QzpcQ2hlY2tvdXRcQVBJXzJ2czJcQVBJXEFQSVxUb2tlbg==?=
Request Headers
:authority:localhost:44305
:method:OPTIONS
:path:/Token
:scheme:https
accept:*/*
accept-encoding:gzip, deflate, sdch, br
accept-language:en-US,en;q=0.8,da;q=0.6,nb;q=0.4
access-control-request-headers:authorization
access-control-request-method:POST
cache-control:no-cache
origin:http://evil.com/
pragma:no-cache
referer:http://localhost:3000/signin
user-agent:Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36
ein eckiger Service sieht so aus:
loginAccount(account: Account): Observable<string> {
var obj = { Email: account.Email, Password: account.Password, grant_type: 'password' };
let headers = new Headers({ 'Content-Type': 'application/json' });
let options = new RequestOptions( {method: RequestMethod.Post, headers: headers });
let body = JSON.stringify(obj);
console.log('loginAccount with:' + body);
return this._http.post('https://localhost:44305/Token', body, options)
.map(this.extractData)
.catch(this.handleError);
}
Wenn ich die AJAX-Funktionen verwende, die in einem API-Projekt enthalten sind:http: //www.asp.net/web-api/overview/security/individual-accounts-in-web-ap dann funktioniert es gut ?? Was mache ich falsch in der Angular POST-Anforderung?