"cannot convert from 'Restsharp.method' to string 'string?'" using RestSharp Any updates

38 views Asked by At

cannot convert from 'Restsharp.method' to string 'string?'

Can't seem to find any indication why every example is like this but doesn't work for me

1

There are 1 answers

0
kishor sharma On

The RestRequest class expects two arguments: string and method. I can see you are only passing the method. Eg:

public RestRequest(string? resource, Method method = Method.Get)

Please pass the string also. The string can be the endpoint of the API you are testing.

Please find the below code, which I used for public API, it should be working.

public void GetBookingDetails1()
{

 
    var restClient = new RestClient("https://restful-booker.herokuapp.com");
    var request = new RestRequest("/booking/1", Method.Get);
    request.AddHeader("accept", "application/json");
 
    var response = restClient.Execute(request);

 
}