c#用httpwebrequest如何模拟抓取这样的网页信息,下面内容是用fiddler抓取的。
CONNECT user.cloudcall.hk:8080 HTTP/1.0
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0;Windows NT 5.1) AppleWebKit
Host: user.cloudcall.hk:8080
Content-Length: 0
Connection: Keep-Alive
Pragma: no-cache
A SSLv3-compatible ClientHello handshake was found. Fiddler extracted the parameters below.
Version: 3.1 (TLS/1.0)
Random: 52 79 06 13 A5 00 6B A2 19 9E 99 D6 BA E3 7E 93 BD 8B A1 26 18 3A 21 E7 F0 31 4C 4F 58 4A 41 73
SessionID: empty
Extensions:
renegotiation_info 00
server_name user.cloudcall.hk
status_request 01 00 00 00 00
elliptic_curves 00 04 00 17 00 18
ec_point_formats 01 00
Ciphers:
[002F] TLS_RSA_AES_128_SHA
[0035] TLS_RSA_AES_256_SHA
[0005] SSL_RSA_WITH_RC4_128_SHA
[000A] SSL_RSA_WITH_3DES_EDE_SHA
[C013] TLS1_CK_ECDHE_RSA_WITH_AES_128_CBC_SHA
[C014] TLS1_CK_ECDHE_RSA_WITH_AES_256_CBC_SHA
[C009] TLS1_CK_ECDHE_ECDSA_WITH_AES_128_CBC_SHA
[C00A] TLS1_CK_ECDHE_ECDSA_WITH_AES_256_CBC_SHA
[0032] TLS_DHE_DSS_WITH_AES_128_SHA
[0038] TLS_DHE_DSS_WITH_AES_256_SHA
[0013] SSL_DHE_DSS_WITH_3DES_EDE_SHA
[0004] SSL_RSA_WITH_RC4_128_MD5
Compression:
[00] NO_COMPRESSION
该回答引用ChatGPT
以下是使用 C# 的 HttpWebRequest 对象模拟抓取您提供的网页信息的示例代码:
using System;
using System.IO;
using System.Net;
using System.Text;
public class Program
{
public static void Main()
{
string url = "https://user.cloudcall.hk:8080/"; // 请求的网址
string userAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1) AppleWebKit"; // 请求时使用的 User-Agent
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); // 创建 HttpWebRequest 对象
request.UserAgent = userAgent; // 设置 User-Agent
request.Method = "GET"; // 设置请求方法为 GET
request.ProtocolVersion = HttpVersion.Version10; // 设置 HTTP 协议版本为 1.0
request.ContentType = "application/x-www-form-urlencoded"; // 设置请求内容类型
request.KeepAlive = true; // 开启 Keep-Alive
request.Timeout = 30000; // 设置请求超时时间为 30 秒
request.Proxy = null; // 不使用代理服务器
request.Headers.Add("Pragma", "no-cache"); // 添加 Pragma 头信息
request.ServicePoint.Expect100Continue = false; // 禁用 100-continue 响应行为
// 发送请求并获取响应
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
// 读取响应内容
using (Stream stream = response.GetResponseStream())
using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
{
string content = reader.ReadToEnd(); // 读取响应内容
Console.WriteLine(content); // 输出响应内容
}
}
}
}
请注意,因为您提供的网址是使用 HTTPS 协议的,因此需要设置 request.ProtocolVersion 属性为 HttpVersion.Version10,以便禁用 HTTP 协议的持久连接(HTTP/1.1 中默认启用)和管道化(HTTP/1.1 中默认启用),避免出现 "The request was aborted: Could not create SSL/TLS secure channel" 错误。另外,需要注意的是,由于 HTTPS 协议使用 SSL/TLS 加密通信,因此需要通过设置 request.ServerCertificateValidationCallback 属性或使用 ServicePointManager.ServerCertificateValidationCallback 事件来验证服务器的 SSL/TLS 证书。