UploadStringAsync不要调用回调

时间:2019-04-02 11:19:43

标签: c#

我已经搜索了一段时间,但是我只看到建议使用httpclient的解决方案,很遗憾我坚持使用webClient,我想知道为什么这不起作用。

static void Main(string[] args)
    {
        var uri = new Uri("MY_SERVER_URL");

        string username = "xxx";
        string password = "xxx";
        string uriParam = "username="
                         + HttpUtility.UrlEncode(username)
                         + "&password="
                         + HttpUtility.UrlEncode(password)
                         + "&client=myClient";

        var client = new WebClient();

        client.UploadStringCompleted += GetProfilesCompleted;
        client.Headers["Content-Type"] = "application/x-www-form-urlencoded";
        client.UploadStringAsync(uri, "POST", uriParam);
    }

    static void GetProfilesCompleted(object sender, UploadStringCompletedEventArgs e)
    {
        Console.WriteLine(e.Error);
        Console.ReadLine();
    }

0 个答案:

没有答案