首页 > 代码库 > HttpWebRequest传值
HttpWebRequest传值
From:发送方
1 class Program 2 { 3 static void Main(string[] args) 4 { 5 string strId = "zhangsan"; 6 string strPassword = "123"; 7 string str = "userid=" + strId; 8 str += "&password=" + strPassword; 9 string url = "http://localhost:7392/WebForm1.aspx";10 byte[] bs = Encoding.ASCII.GetBytes(str);11 HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);12 req.Method = "POST";13 req.ContentType = "application/x-www-form-urlencoded";14 req.ContentLength = bs.Length;15 req.Timeout = 120000;16 try17 {18 using (System.IO.Stream reqStream = req.GetRequestStream())19 {20 reqStream.Write(bs, 0, bs.Length);21 reqStream.Close();22 reqStream.Dispose();23 }24 using (WebResponse wr = req.GetResponse()) //返回25 {26 System.IO.Stream res = wr.GetResponseStream();27 System.IO.StreamReader reader = new System.IO.StreamReader(res);28 string ResStr = reader.ReadToEnd(); //返回结果29 wr.Close();30 Console.WriteLine(ResStr); ;31 }32 }33 catch (Exception ex)34 {35 Console.WriteLine(ex.Message);36 }37 Console.ReadLine();38 }39 }40 }
To:接收方
1 public partial class WebForm1 : System.Web.UI.Page2 {3 protected void Page_Load(object sender, EventArgs e)4 {5 string ID = Request.Form["userid"].ToString();6 string password = Request.Form["password"].ToString();7 }8 }
HttpWebRequest传值
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。