When utilising the RestSharp RestClient method, an error occurs.

Forums .NETWhen utilising the RestSharp RestClient method, an error occurs.
Staff asked 2 years ago

My API uses RestSharp to call a REST API, and the code looks like this.

var testRequest = { My JSON Data}
var clientResponse = new RestClient(".....");
var callrequest = new RestRequest("....", Method.Post);
string authHeader = "...";

callrequest.AddParameter("application/json", testRequest, ParameterType.RequestBody);
callrequest.AddParameter("Authorization", "Bearer " + authHeader, ParameterType.HttpHeader);
var response = clientResponse.Execute(callrequest); <---- //Red line showing here
return Ok(response);

Error

I’m unable to run my software because of the red line. Could someone perhaps explain what the problem is?

Thank you very much.

Yes

John Price replied 1 month ago

Are you using the latest version of Restsharp ?

Umang Ramani replied 1 month ago

Answers (1)

Add Answer
Umang Ramani Marked As Accepted
Staff answered 1 month ago

You are running the most recent RestSharp version. All sync methods have been deprecated since RestSharp utilizes HttpClient beneath the hood, and HttpClient has no sync overloads; everything is async.

Instead of ‘Execute’ use ‘ExecuteAsync’

 

Thank you Umang Ramani

John Price replied 1 month ago

Subscribe

Select Categories