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("<","<"); //HTML = HTML.Replace(">",">"); buf=HTML; return true; } catch (Exception x) { buf=x.Message.ToString(); return false; } }
Rust编程语言群 1036955113
java新手自学群 626070845
java/springboot/hadoop/JVM 群 4915800
Hadoop/mongodb(搭建/开发/运维)Q群481975850
GOLang Q1群:6848027
GOLang Q2群:450509103
GOLang Q3群:436173132
GOLang Q4群:141984758
GOLang Q5群:215535604
C/C++/QT群 1414577
单片机嵌入式/电子电路入门群群 306312845
MUD/LIB/交流群 391486684
Electron/koa/Nodejs/express 214737701
大前端群vue/js/ts 165150391
操作系统研发群:15375777
汇编/辅助/破解新手群:755783453
大数据 elasticsearch 群 481975850
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
java新手自学群 626070845
java/springboot/hadoop/JVM 群 4915800
Hadoop/mongodb(搭建/开发/运维)Q群481975850
GOLang Q1群:6848027
GOLang Q2群:450509103
GOLang Q3群:436173132
GOLang Q4群:141984758
GOLang Q5群:215535604
C/C++/QT群 1414577
单片机嵌入式/电子电路入门群群 306312845
MUD/LIB/交流群 391486684
Electron/koa/Nodejs/express 214737701
大前端群vue/js/ts 165150391
操作系统研发群:15375777
汇编/辅助/破解新手群:755783453
大数据 elasticsearch 群 481975850
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。