2015-10-13 95 views
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數據:

+0

試試這個,我沒有發佈它作爲答案,因爲我沒有嘗試過自己。 'public IHttpActionResult PostXmlData() { string xml =「」; (Request.InputStream!= null){ var stream = new StreamReader(Request.InputStream); var xml = stream.ReadToEnd(); // xml可能被編碼,在使用之前解碼它。 } }' – din

+0

是否有你希望「xmlData」作爲字符串而不是反序列化對象的原因?處理強類型對象比處理字符串要容易得多。 – BMac

回答