Jamie Jamie - 3 months ago 36
C# Question

C# Restsharp not working

I'm trying to make a post request with RestSharp.

var request = new RestRequest("login", Method.POST);
request.AddParameter("email", email);
request.AddParameter("password", password);

List<RestResponse> result = null;

var asyncHandle = client.ExecuteAsync<result>(request, response => {
MessageBox.Show(response.Data.Name);
});


But I receive the error:


'result' is a variable but it's used like a type.


What am I doing wrong?

Answer

This won't compile, as you've noticed.

Without knowing anything about your model, or the response coming back, I'm going to take a guess that this may get you closer to where you want to be.

List<RestResponse> result = null;

result = client.ExecuteAsync<List<RestResponse>>(request, response => {
    MessageBox.Show(response.Data.Name);
});

This at least compiles, because we're passing a type into ExecuteAsync rather than a variable