小程序端代码:
wx.request({
url: getApp().globalData.webApiUrlRoot + '/api/User/test',
method: 'POST',
header: {
'content-type': 'application/json' // 默认值
},
data:{
a:"1"
},
success(res) {
console.log(res);
},
complete(res) {
console.log(res);
}
});
ASP.NET web api :
[HttpPost]
public string test(string a)
{
return "hello";
}
请求结果失败,应答内容:
“No HTTP resource was found that matches the request URI ‘http://localhost:57437/api/User/test’.”
原因为:POST方法只能接收 Content-Type 为 application/x-www-form-urlencoded 和 multipart/form-data 的 POST 数据