这里我试图将一些数据发布到WEbAPI中,但是当我使用headers:{'Content-Type' :'application/json'}
时它工作正常但是当我使用application / Json进行绑定 this.SaveEmp = function (jan) {
console.log('EMP :: '+JSON.stringify(jan));
var saves = $http({
url:"http://localhost:30952/api/EmpSave",
method: "POST",
data: JSON.stringify(jan),
dataType:"json",
contentType: 'application/json; charset=utf-8',
headers: { 'Content-Type': 'application/x-www-form-urlencoded ;charset=utf-8'}
//headers:{'Content-Type' :'application/json'}
})
return saves;
}
时,它的值不会在服务器端进行绑定请建议我如何使用
patient(1).name = 'John Doe';
patient(1).billing = 127.00;
patient(1).test = [79, 75, 73; 180, 178, 177.5; 220, 210, 205];
patient(2).name = 'Ann Lane';
patient(2).billing = 28.50;
patient(2).test = [68, 70, 68; 118, 118, 119; 172, 170, 169];
fields = fieldnames(patient)
%numel is number of elements
for i=1:numel(fields)
fields(i)
patient.(fields{i})
end
答案 0 :(得分:3)
在这里,你需要序列化你的数据因为它是一个交叉平台形式,你需要添加$httpSerializerJQLIKE
并按照程序
$httpParamSerializerJQLike$httpParamSerializerJQLike
this.SaveEmp = function (jan) {
console.log('EMP :: '+JSON.stringify(jan));
var saves = $http({
url:"http://localhost:30952/api/EmpSave",
method: "POST",
dataType: "json",
headers: {
'Accept': 'application/json',
'Content-Type': 'application/x-www-form-urlencoded ;charset=utf-8'
},
data: $httpParamSerializerJQLike(jan),
})
return saves;
}