• 使用HttpWebRequest模拟Web请求


    http post 请求:

              string uri = "http://www.XXXXXXX.com/Default_Login.aspx?usercode=admin&password=123";

                // Get an new instance from factory method.

                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);

                HttpWebResponse response =(HttpWebResponse) request.GetResponse();

                Stream stream = response.GetResponseStream();

                StreamReader reader = new StreamReader(response.GetResponseStream());

                string resultText = reader.ReadToEnd();

                Console.WriteLine(resultText);

                reader.Close();

                stream.Close();

                Console.Read();

      

     

    Http get 请求:

        string uri ="http://www.XXXXXX.com/login.jsp";

                string formdata = "loginid=philzhou&userpassword=777777";

                ASCIIEncoding encoding=new ASCIIEncoding(); 

                byte[] encodeddata = encoding.GetBytes(formdata);

                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);

                request.Method="Post";

                request.ContentType = "application/x-www-form-urlencoded";

                request.ContentLength = encodeddata.Length;

                Stream requestStream = request.GetRequestStream();

        // write form data to request stream.

                requestStream.Write(encodeddata, 0, encodeddata.Length);

                requestStream.Close();

                HttpWebResponse response = (HttpWebResponse)request.GetResponse();

                Stream stream = response.GetResponseStream();

                StreamReader reader = new StreamReader(stream,Encoding.GetEncoding("gb2312"));

                string result = reader.ReadToEnd();

                Console.WriteLine(result);

                reader.Close();

                stream.Close();

                Console.Read();

  • 相关阅读:
    BZOJ 5059: 前鬼后鬼的守护 可并堆 左偏树 数学
    BZOJ 1975: [Sdoi2010]魔法猪学院 大水题 第k短路 spfa
    BZOJ 4003: [JLOI2015]城池攻占 左偏树 可并堆
    BZOJ 3091: 城市旅行 lct 期望 splay
    2018/3/27 省选模拟赛 140分
    BZOJ 2959: 长跑 lct 双联通分量 并查集 splay
    2018/3/26 省选模拟赛 60分
    快速排序
    插入排序法
    快速排序的两种方法
  • 原文地址:https://www.cnblogs.com/philzhou/p/2082803.html
Copyright © 2020-2023  润新知