我正在尝试将电子邮件地址和密码发布到服务器以接收 JSON。但是,以下代码从服务器接收到响应,表明未收到 POST 数据。
private void BtnSignIn_Click(object sender, RoutedEventArgs e)
{
String email = Email.Text;
String password = Password.Password;
String data = "email=" + email + "&password=" + password;
WebClient wc = new WebClient();
Uri uri = new Uri("http://api.server.com/login");
wc.UploadStringCompleted += new UploadStringCompletedEventHandler(wc_UploadStringCompleted);
wc.UploadStringAsync(uri, "POST", data);
}
该字符串data
以格式正确生成email=test@test.com&password=hunter2
。
和事件处理函数...
private void wc_UploadStringCompleted(object sender, UploadStringCompletedEventArgs e)
{
MessageBox.Show(e.Result);
}
我需要做些什么来确保将字段正确发布到服务器?谢谢!