简体   繁体   English

C#Restsharp无法正常工作

[英]C# Restsharp not working

I'm trying to make a post request with RestSharp . 我正在尝试通过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 至少可以编译,因为我们将类型传递给ExecuteAsync而不是变量

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);
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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