2013-01-11 52 views
0

我有一個生成XML的php服務。我如何解析C#中的XML?我試圖用這樣的:Windows Phone 8 Web請求異步調用XML

WebRequest request = WebRequest.Create("http://devstage.jokeroo.com/rest.php"); 
request.Method = "GET"; 
request.ContentType = "text/html"; 
IAsyncResult result = request.BeginGetResponse(RequestCallback, request); 

private void RequestCallback(IAsyncResult ar) 
    { 
     var request = ar.AsyncState as WebRequest; 
     Stream reader = request.EndGetResponse(ar).GetResponseStream(); 
     //use this reader to read the content 
    } 

但它不斷拋出此異常:

'System.Net.ProtocolViolationException'類型的異常出現在System.Windows.ni.dll但在用戶代碼

任何建議沒有處理?

回答

2

擺脫這一行:

request.ContentType = "text/html"; 

你正在做一個GET請求,因此沒有請求主體;因此,設置內容類型(對於不存在的和不受支持的HTTP請求主體)是什麼導致了你的錯誤。