I tried to find a solution for this, but all that works for previous versions of ASP.Net.
I work with JWT authentication middleware and have the following method:
private async Task GenerateToken(HttpContext context) { var username = context.Request.Form["username"]; var password = context.Request.Form["password"];
Gets the submitted data as if it were form data, but my Angular 2 frontend sends the data as JSON.
login(username: string, password: string): Observable<boolean> { let headers = new Headers({ 'Content-Type': 'application/json' }); let options = new RequestOptions({ headers: headers }); let body = JSON.stringify({ username: username, password: password }); return this.http.post(this._api.apiUrl + 'token', body, options) .map((response: Response) => { }); }
My preferred solution is to send it as JSON, but I could not get the data. I know that it is being sent because I see it as a violinist, and if I use Postman and just submit the form data, it works fine.
Basically, I just need to figure out how to change this line to read json data.
var username = context.Request.Form["username"];
Jhorra
source share