网址:https://pgi.kaipanla.com/w12/share/PContent2.html?AID=1548&tag=2&atype=ord
浏览器打开可以正常显示内容,使用WebRequest无法获得网页内容。
请给出demo
C# 采集网页,浏览器可以打开,程序采集提示错误
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
2条回答 默认 最新
- threenewbee 2018-08-13 12:23关注
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; using System.Net; namespace Q697477 { class Program { public static string PostData(string url, string param) { string strURL = url; System.Net.HttpWebRequest request; request = (System.Net.HttpWebRequest)WebRequest.Create(strURL); request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded; charset=UTF-8"; string paraUrlCoded = param; byte[] payload; payload = System.Text.Encoding.UTF8.GetBytes(paraUrlCoded); request.ContentLength = payload.Length; Stream writer = request.GetRequestStream(); writer.Write(payload, 0, payload.Length); writer.Close(); System.Net.HttpWebResponse response; response = (System.Net.HttpWebResponse)request.GetResponse(); System.IO.Stream s; s = response.GetResponseStream(); string StrDate = ""; string strValue = ""; StreamReader Reader = new StreamReader(s, Encoding.UTF8); while ((StrDate = Reader.ReadLine()) != null) { strValue += StrDate + "\r\n"; } return strValue; } static void Main(string[] args) { string s = PostData("https://article.kaipanla.com/w1/api/index.php?apiv=w12&PhoneOSNew=3", "c=ForumsMsgJX&a=GetInfo&MsgID=1548&Tag=1"); Console.WriteLine(s); } } }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报