簡體   English   中英

Windows Phone 8 Web請求異步調用XML

[英]Windows Phone 8 Web Request Async Call for XML

我有一個生成XML的php服務。 如何在C#中解析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.Windows.ni.dll出現'System.Net.ProtocolViolationException'類型的異常,但未在用戶代碼中處理

有什么建議么?

擺脫這條線:

request.ContentType = "text/html";

您正在提出GET請求,因此沒有請求正文; 因此,設置內容類型(對於不存在和不支持的HTTP請求主體)是導致錯誤的原因。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM