0

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?

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.