所以我在Angular中发送一个Http.post作为this遇到了类似的情况。但是,我确实已导入Header类,并且我仍然首先获得text / plain ContentType。这就是我所拥有的:
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
);
}
}
任何人都知道是否有办法删除此标题?或者这可能是Chrome正在做的事情吗?
答案 0 :(得分:1)
Welp,我是个白痴......
'内容类型'
不的
'的ContentType'
如果我使用正确的标题,请帮助我......现在我会把头撞到墙上。