上代码,方便查看【摘抄】
System.Net.WebClient WebClientObj = new System.Net.WebClient(); System.Collections.Specialized.NameValueCollection PostVars = new System.Collections.Specialized.NameValueCollection(); PostVars.Add("userid", userid); byte[] byRemoteInfo = null; string url = "http://~"; byRemoteInfo = WebClientObj.UploadValues(url, "POST", PostVars); string str = System.Text.Encoding.UTF8.GetString(byRemoteInfo);
使用案例:
protected void ebtSync_Click(object sender, EventArgs e) { DataTable dtChoose = GridShow1.ChooseTable; System.Net.WebClient WebClientObj = new System.Net.WebClient(); System.Collections.Specialized.NameValueCollection PostVars = new System.Collections.Specialized.NameValueCollection(); PostVars.Add("usercode", "aa"); PostVars.Add("module", "bb"); byte[] byRemoteInfo = null; string url = "http://localhost:8080/DaiBan.ashx"; byRemoteInfo = WebClientObj.UploadValues(url, "POST", PostVars); string str = System.Text.Encoding.UTF8.GetString(byRemoteInfo); testEntity result = new JavaScriptSerializer().Deserialize<testEntity>(str); if (str == "success") { this.Message("同步成功!"); } else { this.Message("同步失败!"); } }