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     }
  • 相关阅读:
    .net 流读取
    c#小Tip:数字格式化显示
    VS.NET优化编译速度
    Application.Run()和Form.Show()的区别
    如何利用系统函数操作文件夹及文件
    设计优秀的用户界面
    我妈过来了
    帮你免于失业的十大软件技术(转抄)
    正试图在 OS 加载程序锁内执行托管代码
    NASA World Wind
  • 原文地址:https://www.cnblogs.com/yf2011/p/3989239.html
Copyright © 2011-2022 走看看