I am getting a “System.Net.ProtocolViolationException: Operation is not valid due to the current state of the object.” error when trying to call
var request = (HttpWebRequest)WebRequest.Create(uri);
request.Method = "GET";
request.ContentType = "text/xml";
request.BeginGetRequestStream(RequestCompleted, request);
I suspect this may be because you are performing a
BeginGetRequestStreamon a request object for which you have specified the “GET” method.When performing a “GET” the server will not be expecting an entity body in the request hence you should proceed straight to
BeginGetResponse. Also specifying aContentTypeon the request is not necessary, it specifies the type of content being sent in the entity body of the request but as stated a “GET” doesn’t send any content it only gets content.