0
点赞
收藏
分享

微信扫一扫

Angular HttpClient POST 服务器(springboot)获取不到参数问题

Angular HttpClient POST 服务器获取不到参数问题

参数是一串json字符串,而不是一个的参数

改前

Angular HttpClient POST 服务器(springboot)获取不到参数问题_json字符串

 

 改后

Angular HttpClient POST 服务器(springboot)获取不到参数问题_服务器_02

 

 

改前:

//调用登录接口
var api = 'http://127.0.0.1/authentication/form';
var dd=this.validateForm.value;
const httpOptions = {
headers: new HttpHeaders({'content-type': 'application/x-www-form-urlencoded'})
};
this.http.post(api,{
"username":"admin",
"password":"123456",
"imageCode":"2313"
},httpOptions).subscribe((response)=>{
console.log(response);
});

改后:

transformRequest(data) {
var str = '';
for (var i in data) {
str += i + '=' + data[i] + '&';
}
str.substring(0, str.length - 1);
return str;
};


//调用登录接口
var api = 'http://127.0.0.1/authentication/form';
var dd=this.validateForm.value;
const httpOptions = {
headers: new HttpHeaders({'content-type': 'application/x-www-form-urlencoded'})
};
this.http.post(api,this.transformRequest({
"username":"admin",
"password":"123456",
"imageCode":"2313"
}),httpOptions).subscribe((response)=>{
console.log(response);
});

 

 

 

 

Angular HttpClient POST 服务器获取不到参数问题



举报

相关推荐

0 条评论