zoukankan      html  css  js  c++  java
  • 使用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();

  • 相关阅读:
    windows7 Cygwin 下安装 YouCompleteMe 插件
    挣值管理(EVT)
    关键路径法
    PERT(计划评审技术,Program Evaluation an Review Technique)
    孙子兵法--你如何来做好事情
    项目经理解决冲突的模式
    PMP考试--成本管理中常用的概念
    PMP考试--挣值如何计算?
    PMP-产品范围与项目范围区别
    PMP考试--价值工程法
  • 原文地址:https://www.cnblogs.com/philzhou/p/2082803.html
Copyright © 2011-2022 走看看