0
我奋力王氏发布XML原始数据,以我的WebAPI控制器,传递的值总是在控制器侧空子....发送XML原始数据总是空
这里我的代码:
请求
Query.support.cors = true;
$.ajax({
type: "POST",
url: axForm.EndPoint + "api/items/PostXmlData",
contentType: "application/xml",
data: {xmlData: axForm.QvXmlForm},
async: false,
success: function (response) {
$('#tab1').append(response);
},
error: function (xhr, ajaxOptions, thrownError) {
//alert(xhr.responseText);
}
});
}
的WebAPI方法
[ActionName("PostXmlData")] [System.Web.Http.AcceptVerbs("POST")] [System.Web.Http.HttpPost] public IHttpActionResult PostXmlData([FromBody]string xmlData) { ... }
个
发送XML数据:
试试这个,我没有发布它作为答案,因为我没有尝试过自己。 'public IHttpActionResult PostXmlData() { string xml =“”; (Request.InputStream!= null){ var stream = new StreamReader(Request.InputStream); var xml = stream.ReadToEnd(); // xml可能被编码,在使用之前解码它。 } }' – din
是否有你希望“xmlData”作为字符串而不是反序列化对象的原因?处理强类型对象比处理字符串要容易得多。 – BMac