Alek Arsovski
Alek Arsovski

Reputation: 339

Windows Phone 8 Web Request Async Call for XML

I have a php service that generates XML. How can I parse the XML in C#? I tried using something like this:

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
    }

But it keeps throwing this exception:

An exception of type 'System.Net.ProtocolViolationException' occurred in System.Windows.ni.dll but was not handled in user code

Any suggestions?

Upvotes: 0

Views: 1354

Answers (1)

Jim O'Neil
Jim O'Neil

Reputation: 23754

Get rid of this line:

request.ContentType = "text/html";

You're making a GET request so there is no request body; therefore, setting the content type (for a non-existent and non-supported HTTP request body) is what's causing your error.

Upvotes: 2

Related Questions