我错过了一个新的webapi技巧 - 我试图通过一个帖子请求提交一个xml字符串而没有太多运气.
前端使用这样的jQuery:
$(document = function () {
$("#buttonTestAPI").click(function () {
var d = " <customer><customer_id>1234</customer_id></customer>";
$.ajax({
type: 'POST',
contentType: "text/xml",
url: "@Url.Content("~/api/Customer/")",
data: d,
success: function (result) {
var str = result;
$("#output").html(str);
}
});
});
});
Run Code Online (Sandbox Code Playgroud)
我的控制器目前非常简单 - 只是后期操作的默认设置 - 尝试返回传入的内容:
public string Post(string value)
{
return value;
}
Run Code Online (Sandbox Code Playgroud)
但是,"值"重复为空.奇怪的是,当我在jquery中更改我的数据时,就像这样:
d = "<customer_id>1234</customer_id>";
Run Code Online (Sandbox Code Playgroud)
然后我在控制器中得到"值"为1234.
如何访问控制器中更复杂的xml字符串?