I have the following simple code, running with RestSharp v107.3.0.0, targeting .NET v4.8:
var restClientOptions = new RestSharp.RestClientOptions("mybaseurl") {
ThrowOnAnyError = true,
Timeout = timeout
};
var restClient = new RestSharp.RestClient(restClientOptions);
var restRequest = new RestSharp.RestRequest("myendpoint", RestSharp.Method.Get)
.AddParameter(new RestSharp.HeaderParameter("Content-Type", "application/json"));
var response = this.RestClient.ExecuteAsync(restRequest).GetAwaiter().GetResult();
However, when this code executes, I get the following error:
Type: System.Net.ProtocolViolationException
System.Net.ProtocolViolationException: Cannot send a content-body with this verb-type.
at RestSharp.RestClient.ThrowIfError(RestResponse response)
at RestSharp.RestClient.<ExecuteAsync>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
Note that in the above code that I am NOT setting a body, but the error message implies that I did.
Also, I can execute POST operations without problem.
Has anyone else seen this issue? Am I missing something obvious?
Thanks, Dave