我通过Angular2向表达服务器发送数据但是以疯狂的方式获取数据。但它与邮递员合作很好。
Angular2代码是:
import {Injectable} from '@angular/core';
import {Http, Headers, RequestOptions} from '@angular/http';
@Injectable()
export class LoginService{
private _options = new RequestOptions({ headers: new Headers({ 'Content-Type': 'application/x-www-form-urlencoded' }) });
constructor(private _http: Http){ }
login(credentials: Object){
return this._http.post('/api/login', JSON.stringify(credentials), this._options);
}
}
快递中的Gettin数据如下:
{ '{"username":"XXXXXXXX","password":"XXXXXXXX"}': '' }
但是在邮递员中按预期发送数据时
{"username":"XXXXXXXX","password":"XXXXXXXX"}
帮助我。
答案 0 :(得分:0)
您正在对数据进行字符串化处理:
return this._http.post('/api/login', JSON.stringify(credentials), this._options);
而是这样做:
return this._http.post('/api/login', credentials, this._options);