我编写了一个程序,写了一个POST类,在POST类中使用webclient的UploadStringAsync。
然后通过UploadStringCompletedEventHandler,可以得到e.result。
但是我想把e.result传回去主程序的textblock.text中。
请问应该要怎么做...求具体代码...
---------------------------------post类---------------------------------------------
public class PostClass
{
public string result { get; set; }
public void Post(string url,string data)
{
WebClient WC = new WebClient();
WC.UploadStringCompleted += new UploadStringCompletedEventHandler((sender, e) => {result = e.Result; });
WC.UploadStringAsync(new Uri(url), "POST", data);
}
---------------------------------------主程序----------------------------------------
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
PostClass PC = new PostClass();
string URL = "http://youxi.baidu.com/ajax_user_login.xhtml";
string data = "c=login&loginName="+Uri.EscapeUriString("帐号")+"&password=密码";
PC.Post(URL, data);
//MessageBox.Show(PC.result);
}
}