C#使用HttpWebRequest不会';行不通

C#使用HttpWebRequest不会';行不通,c#,C#,打开时,使用HttpWebRequest。你为什么来访 无法获取内部数据 string strResult = ""; try { string url = "https://web4.sa8888.net/sport/Games.aspx?lang=3&device=pc"; ServicePointManager.Expect100Continue = true; ServicePointManager.SecurityProtocol = System.

打开时,使用
HttpWebRequest
。你为什么来访

无法获取内部数据

string strResult = "";
try
{
    string url = "https://web4.sa8888.net/sport/Games.aspx?lang=3&device=pc";

    ServicePointManager.Expect100Continue = true;
    ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;

    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
    request.AutomaticDecompression = DecompressionMethods.GZip;

    request.Method = "GET";
    request.Timeout = 30000;
    request.KeepAlive = true; 
    request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36";
    request.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
    request.Headers.Set("Pragma", "no-cache");
    //request.ContentLength = bs.Length;
    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
    Stream streamReceive = response.GetResponseStream();
    Encoding encoding = Encoding.GetEncoding("UTF-8");
    StreamReader streamReader = new StreamReader(streamReceive, encoding);
    strResult = streamReader.ReadToEnd();
}
catch (Exception e)
{
    MessageBox.Show(e.Message);
}
textBox1.Text=strResult;

您链接到的页面是使用javascript构建的,因此您看到的不是源代码的一部分。例如,若你们看一看,你们会发现他们在那个里构建了大量的表数据

HttpWebRequest只会为您获取一个文件,它不会像真正的浏览器那样运行javascript。这就是为什么你没有得到你想要的数据


再看一看,他们似乎是通过WebSocket以二进制格式传输信息,所以这是一个非常简单的设置,可以将数据取出(可能至少部分构建是为了避免人们刮取他们的数据)。

你得到了什么?一个例外,一个空洞的刺痛还是什么?嗨,卡尔·约翰斯格伦,那么我的程序应该如何重写呢?HttpWebRequest+WebSocket?或者哪一方有例子可供参考?感谢WebSockets似乎是必需的,但它需要更多的研究/逆向工程来找出如何实现这一点。这是一个很大的答案在这里如此。阅读websockets,然后开始阅读该站点上的JavaScript文件,以了解其具体工作原理,这是我能给您的最好建议。好的,我试着感谢您的回答