zoukankan      html  css  js  c++  java
  • C#读取网页

    public bool getweb(string strURL,out string buf)
      {
       buf="";
       try
       {
        //Uri url=new Uri(strURL,false);
        HttpWebRequest request;
        request = (HttpWebRequest)WebRequest.Create(strURL);
        request.Method="POST"; //Post请求方式
        request.ContentType="text/html;charset=gb2312"; //内容类型
        string paraUrlCoded = System.Web.HttpUtility.UrlEncode(""); //参数经过URL编码
        byte[] payload;
        payload = System.Text.Encoding.GetEncoding("GB2312").GetBytes(paraUrlCoded); //将URL编码后的字符串转化为字节
        request.ContentLength = payload.Length; //设置请求的ContentLength
        Stream writer = request.GetRequestStream(); //获得请求流
        writer.Write(payload,0,payload.Length); //将请求参数写入流
        writer.Close(); //关闭请求流
        HttpWebResponse response;
        response = (HttpWebResponse)request.GetResponse(); //获得响应流
        Stream s;
        s = response.GetResponseStream();
        StreamReader objReader = new StreamReader(s,System.Text.Encoding.GetEncoding("GB2312"));
        string HTML = "";
        string sLine ="";
        int i = 0;
        while (sLine!=null)
        {
         i++;
         sLine = objReader.ReadLine();
         if (sLine!=null)
          HTML += sLine;
        }
        //HTML = HTML.Replace("&lt;","<");
        //HTML = HTML.Replace("&gt;",">");
        buf=HTML;
        return true;
       }
       catch (Exception x)
       {   
        buf=x.Message.ToString();
        return false;    
       }
      }
     
  • 相关阅读:
    upc组队赛1 黑暗意志【stl-map】
    upc组队赛1 闪闪发光 【优先队列】
    upc组队赛1 流连人间的苏苏
    POJ 2387 Til the Cows Come Home 【最短路SPFA】
    POJ 2421 Constructing Roads 【最小生成树Kruscal】
    qrcode-使用
    submlie 配置php运行
    composer 安装laravel
    composer 配置镜像
    Laravel-队列
  • 原文地址:https://www.cnblogs.com/cfas/p/3154399.html
Copyright © 2011-2022 走看看