C# 为什么我的HttpRequest*总是*触发CDN?
我使用fiddler模拟brwoser的请求。 在浏览器中,我不需要任何cookies就可以得到我想要的东西,即使在新机器、新IP上,也可以成功。 但当我使用HttpRequest时,它总是返回cdn结果,这不是我所期望的,也不例外。我一次也没成功过 这是url,随机数可以更改,这无关紧要 这就是我所做的:C# 为什么我的HttpRequest*总是*触发CDN?,c#,web,https,C#,Web,Https,我使用fiddler模拟brwoser的请求。 在浏览器中,我不需要任何cookies就可以得到我想要的东西,即使在新机器、新IP上,也可以成功。 但当我使用HttpRequest时,它总是返回cdn结果,这不是我所期望的,也不例外。我一次也没成功过 这是url,随机数可以更改,这无关紧要 这就是我所做的: public static void InitializeEnvironment() { ServicePointManager.UseNagleAlgorithm
public static void InitializeEnvironment()
{
ServicePointManager.UseNagleAlgorithm = true;
ServicePointManager.Expect100Continue = true;
ServicePointManager.CheckCertificateRevocationList = true;
ServicePointManager.DefaultConnectionLimit = int.MaxValue;
ServicePointManager.ServerCertificateValidationCallback += delegate (object sender, X509Certificate cert, X509Chain chain, SslPolicyErrors error) { return true; };
ServicePointManager.SecurityProtocol = (SecurityProtocolType)192 | (SecurityProtocolType)768 | (SecurityProtocolType)3072;// ServicePointManager.CheckCertificateRevocationList = true;
}
private void Login(CookieContainer cc)
{
HttpWebRequest request = null;
try
{
request = (HttpWebRequest)HttpWebRequest.Create(string.Format("https://www.yczy00.com/valid_code?t={0}&user_name=", RealRandom.GetRandomDouble().ToString("f16")));
request.Method = "GET";
request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:59.0) Gecko/20100101 Firefox/59.0";
request.Accept = "*/*";
request.Headers.Add("Accept-Language", "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2");
request.Headers.Add("Accept-Encoding", "gzip, deflate, br");
request.KeepAlive = true;
request.Headers.Add("Pragma", "no-cache");
request.Headers.Add("Cache-Control", "no-cache");
request.Referer = "https://www.yczy00.com/";
request.CookieContainer = cc;
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
{
string html = reader.ReadToEnd();
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
您能否澄清“it可以成功”和“it总是返回CDN结果”的含义?您希望返回什么?实际返回了什么?什么是“返回CDN结果”?您希望得到什么结果?我将图像作为返回(内容类型:image/jpeg),当它失败时,返回内容类型:text/html@joh@JohnWu1111111111111111服务器的行为完全是由应用程序定义的,因此如果没有更多的细节,我无法向您提供建议。我能给你的唯一提示就是遵循基本的问题隔离程序,检查小提琴手轨迹是否有任何差异,无论差异有多小。