v107.3 issue with Method.Get

702 views
Skip to first unread message

David Hukill

unread,
Mar 1, 2022, 4:10:36 PM3/1/22
to RestSharp
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

David Hukill

unread,
Mar 2, 2022, 9:35:26 AM3/2/22
to RestSharp
Forgot to mention that this request works as expected in Postman.

Also, I found the following article that seems to imply that others are having the same problem:


Apparently this is an issue in .NET Framework, but not in .NET Core.

Cheers, Dave

David Hukill

unread,
Mar 2, 2022, 8:01:39 PM3/2/22
to RestSharp
Update: I switched to version 106.15, and it works perfectly. Definitely  a problem with v107.

Cheers, Dave

Alexey Zimarev

unread,
Mar 3, 2022, 4:25:09 PM3/3/22
to RestSharp
It's, indeed, how HttpClient works when targeting .NET Framework.
Reply all
Reply to author
Forward
0 new messages