我已经搜索了一段时间,但是我只看到建议使用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();
}