【发布时间】:2016-01-17 19:26:17
【问题描述】:
我正在尝试接收带有一些 json 字符串的发布请求
var contentType ="application/x-www-form-urlencoded; charset=utf-8";
$.ajax({
type: "POST",
data: JSON.stringify(fileData),
url: "http://hercules/JsonTest/api/Getjson/sendData",
contentType: contentType,
processData: false,
error: function (qXHR, textStatus, errorThrown) {
alert("failure: " + qXHR.status + ":" + textStatus + errorThrown);
},
success : function(data) {
alert("Success : " + data);
}
});
在我的 webapi 中
[System.Web.Http.HttpPost]
[System.Web.Http.ActionName("sendData")]
public string sendData([FromBody] string jsonString)
{
logData("Entering SendData : " + jsonString);
return "Success";
}
但是,webapi 中没有收到我发布的 jsonString。它抛出错误值不能为空。 参数名称:值
可能是什么原因。 我直接在我的视觉工作室中测试代码,同样工作正常。但是一旦我在机器上发布了相同的内容,并尝试通过 jsFiddle 访问,则字符串显示为空。
【问题讨论】:
标签: asp.net-web-api