zoukankan      html  css  js  c++  java
  • 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             try
    17             {
    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.Page
    2     {
    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     }
  • 相关阅读:
    matlab cell
    matlab linux 快捷键设置——有问题还是要解决
    latex 小结
    TOJ 1258 Very Simple Counting
    TOJ 2888 Pearls
    HDU 1248 寒冰王座
    TOJ 3486 Divisibility
    TOJ 3635 过山车
    TOJ 1840 Jack Straws
    HDU 4460 Friend Chains
  • 原文地址:https://www.cnblogs.com/yf2011/p/3989239.html
Copyright © 2011-2022 走看看