0
我試圖從POSTMAN重新創建這些設置,允許我成功驗證到我的服務器。然而,在Angular 2中,我沒有看到如何在'application/json'中設置'raw'設置,因爲它需要在兩個地方:一個在Headers中,另一個在Body中。在Angular 2中重新創建郵差設置
//Config file
import { Headers } from 'angular2/http';
export class Config {
baseAPIUrl: string = 'http://api:8080/';
headers: Headers
constructor() {
this.headers = new Headers();
this.headers.append('Access-Control-Allow-Origin', 'http://api:8080');
this.headers.append('Content-Type', 'application/json');
}
// Session service
login(email: string, password: string) {
var sessionSubscription = this.http.post(this.config.baseAPIUrl + 'auth/session', JSON.stringify({ email , password }), {
headers: this.config.headers });
return sessionSubscription.subscribe((res) => {
console.log(res);
},
(error) => console.log('error', error));
}
它們是兩個單獨的文件。我通過'this.config'訪問所有配置。只是當我將JSON(應用程序/文本)更改爲其他任何內容時,它會給我一個錯誤:Status 422 Unprocessable Entity – Ade
'JSON(application/text)'?不知道你在做什麼。 – Sasxa
抱歉,我的意思是'JSON(application/json)' – Ade