0

So I'm running into a similar situation with sending an Http.post in Angular as this. However, I do have the Header class imported, and I am still getting the text/plain ContentType first. Here is what I have:

import { Component } from '@angular/core';
import { Http, Headers } from '@angular/http';

import {User} from "../classes/user";

@Component({
    selector: 'login',
    templateUrl: 'frontend/login/view.html',
    styleUrls: ['frontend/login/style.css'],
})

export class LoginComponent {
    email: string;
    emailError: boolean = false;
    password: string;
    passwordError: boolean = false;
    persist: boolean;
    user: User;

    constructor(
        private _http: Http
    ) { }

    login() {
        var headers = new Headers();
        headers.append('ContentType', 'application/json');
        this.emailError = !this.email;
        this.passwordError = !this.password;

        if (this.emailError || this.passwordError) { return; }

        this._http.post('http://localhost:81/login', JSON.stringify({username: this.email, password: this.password}), { headers: headers })
            .map(res => res.json())
            .subscribe(
                user => this.user = user
            );
    }
}

Anyone know if there's a way to strip this header? or is this possible something that Chrome is doing on it's own?

Community
  • 1
  • 1
Dave V
  • 1,966
  • 9
  • 18
  • A little further clarification, it does appear that Firefox does this as well...but it puts it as the second header. So I'd say this isn't my problem, in either case, I get a 400 Bad Request back. But if I hit this same API from something like say Postman. It works. – Dave V May 11 '16 at 17:56
  • And some further clarification...if I add a text/plain header in Postman...it fails...so maybe that is it...so back to the original question...anyone know how to remove that header? – Dave V May 11 '16 at 18:02

1 Answers1

1

Welp, I'm an idiot...

'Content-Type'

not

'ContentType'

Helps if I use the right header...I'll go bang my head against a wall now.

Dave V
  • 1,966
  • 9
  • 18