简体   繁体   中英

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?

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

Error is saying it clearly. You need to give type instead of variable name result, similar to the following:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM