2015-07-20 47 views
0

我有一個Web Api應用程序。請求的URL包含大量的xml數據。如何發佈xml到api控制器並閱讀內容

http://localhost:15178/api/access?<xml><data>result</data></xml> 


[HttpGet] 
public IHttpActionResult Get() 
    { 
    string requstedXml = String.Empty; 
    var t = this.Request.Content.ReadAsStringAsync().ContinueWith(s => 
    { 
     requstedXml = s.Result; 
    }); 
    t.Wait(); 

上面的代碼總是空的。我怎樣才能讀取XML?

回答

1

您不是將API張貼到API,而是執行GET,因此Request.Content爲空。

您可以從查詢字符串中獲取XML,或者在您的URL和Get方法中設置參數名稱。

http://localhost:15178/api/access?xml=<xml><data>result</data></xml> 

public IHttpActionResult Get(string xml) 
{ 
} 

通過查詢字符串發送大塊的XML雖然看起來不是一個很好的方法。