角度2 URL编码在http post中
我尝试通过post whit angular2使用服务。这是我的代码:角度2 URL编码在http post中,post,angular,ionic2,angular-http,Post,Angular,Ionic2,Angular Http,我尝试通过post whit angular2使用服务。这是我的代码: var m_dataRequest = this.buildLoginUserPasswordRequest(password, key); let headers = new Headers({ 'Accept': '*/*', 'Accept-Encoding': 'gzip, deflate, br', 'Accept-Language': 'es-ES,
var m_dataRequest = this.buildLoginUserPasswordRequest(password, key);
let headers = new Headers({
'Accept': '*/*',
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'es-ES,es;q=0.8,en;q=0.6',
'Content-Type': 'application/x-www-form-urlencoded',
});
let options = new RequestOptions({ headers: headers });
let body = new URLSearchParams();
body.set("message", JSON.stringify(m_dataRequest));
body.set("webService", "authService");
return this.http
.post(this.Url, body.toString(), options)
.toPromise()
.then(this.extractData)
.catch(this.handleError);
private buildLoginUserPasswordRequest(password:string, key:string): any {
var m_dataRequest = {
"ser:nativeAppAuth": {
"-xmlns:ser": "http://services.mobileappbc.ws.todo1.com/",
"password": this.utilService.buidRSAPass(password, t1Assertion),
"key": key,
"deviceInfo": this.utilService.getDeviceInfo()
}
};
return m_dataRequest;
}
内容类型为application/x-www-form-urlencoded,因为后端需要这种方式的信息。
我的问题是“:”字符未转换为等效的urlencoded%3A+。
这会导致我的后端服务出现问题
有解决这个问题的建议吗?
谢谢 Json.stringify不会对数据进行uri编码,因为它可以处理数据。 您需要使用uriencode()