0

我不知道我在这里做错了什么。它应该是非常基本的。服务器返回 JSON,我向它发送用户名和密码

var email = emailLoginTextBox.Text;
var password = passwordLoginTextBox.Password;
var client = new RestClient("http://www.mywebsite.com");
var request = new RestRequest("signin", Method.POST);

request.AddParameter("em", email);
request.AddParameter("pw", password);
var result = "";

client.ExecuteAsync(request, (response) =>
                                             {
                                                 result = response.Content;
                                             }
                );
Console.Write(result);

executeAsync 调用似乎什么都不做。结果始终为空。我正在使用通过 Nuget 安装的最新 Restsharp。同样在 Fiddler 中,调用 executeAsync 时没有流量。这是正常的吗?

4

1 回答 1

2

您的请求是异步的。Console.WriteLine 在回调之前执行。

尝试这个

var email = emailLoginTextBox.Text;
var password = passwordLoginTextBox.Password;
var client = new RestClient("http://www.mywebsite.com");
var request = new RestRequest("signin", Method.POST);

request.AddParameter("em", email);
request.AddParameter("pw", password);
var result = "";

client.ExecuteAsync(request, (response) =>
    {
        result = response.Content;
        Console.Write(result);
    }
);
于 2012-09-13T11:13:30.797 回答