简体   繁体   中英

Angular2 RC1, HTTP POST Header

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM