I simply obtained this exemption (ProtocolViolationException) in my .NET 2.0 application (running on windows mobile 6 traditional emulator). What confprovides me is that as much as i know, I have not added any kind of content body, unless I"ve inadvertently done it somehow. My code is below (very simple). Is tright here anypoint else i have to carry out to convince .NET that this is simply a http GET?

//run gain and also grab responseWebRepursuit request = WebResearch.Create(obtain.AbsoluteUri + args);repursuit.Method = "GET";Stream stream = repursuit.GetRequestStream(); //


You are watching: Cannot send a content body with this verb type

*

*

Don"t acquire the repursuit stream, rather sindicate. GET repursuits do not usually have bodies (even though it"s not technically prohibited by HTTP) and WebRepursuit doesn"t assistance it - but that"s what calling GetRequestStream is for, offering body data for the repursuit.

Given that you"re trying to read from the stream, it looks to me favor you actually desire to obtain the response and also check out the response stream from that:

WebRequest research = WebRepursuit.Create(get.AbsoluteUri + args);repursuit.Method = "GET";making use of (WebResponse response = research.GetResponse()) using (Stream stream = response.GetResponseStream()) XmlTextReader reader = new XmlTextReader(stream); ...

*

*

I had the comparable problem making use of Flurl.Http:

Flurl.Http.FlurlHttpException: Call failed. Cannot send a content-body via this verb-kind. GET http://******:8301/api/v1/agents/**** ---> System.Net.ProtocolViolationException: Cannot send a content-body via this verb-form.

The trouble was I supplied .WithHeader("Content-Type", "application/json") as soon as creating IFlurlRequest.


*



See more: " I Want The One I Can T Have Lyrics, I Want The One I Can'T Have Lyrics

Due to the fact that you didn"t specify the Header.

I"ve included an extended example:

var repursuit = (HttpWebRequest)WebRepursuit.Create(strServer + strURL.Split("&")<1>.ToString());Header(ref research, p_Method);

And the approach Header:

exclusive void Header(ref HttpWebRequest p_request, string p_Method) p_request.ContentType = "application/x-www-form-urlencoded"; p_request.Method = p_Method; p_research.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows CE)"; p_request.Host = strServer.Split("/")<2>.ToString(); p_repursuit.Accept = "*/*"; if (String.IsNullOrEmpty(strURLReferer)) p_request.Referer = strServer; else p_request.Referer = strURLReferer; p_request.Headers.Add("Accept-Language", "en-us "); p_research.Headers.Add("UA-CPU", "x86 "); p_request.Headers.Add("Cache-Control", "no-cache "); p_request.KeepAlive = true;