C# HttpWebRequest 返回错误 403如何修复 C# 中 HttpWebRequest 的 403 错误

问题描述

我一直在尝试在某个网站上使用 HttpWebRequest,但在我尝试访问的特定网站上一直被禁止使用 403。我想知道是否有任何方法可以解决它。我一直在尝试添加一堆标题解决这个问题,但没有任何效果

 Uri uri = new Uri("https://www.wakfu.com");
            CookieContainer cookies = new CookieContainer();
            HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(uri);
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
            myRequest.UserAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML,like Gecko) Chrome/55.0.2883.87 Safari/537.36"; ;
            myRequest.Method = "GET";
            myRequest.CookieContainer = cookies;
            myRequest.Headers.Add("Accept-Language","en;q=0.8");
            myRequest.Accept = "text/html";
            myRequest.Headers.Add("Accept-Encoding","gzip,deflate");
            myRequest.ContentType = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8";
            myRequest.Headers.Add("Upgrade-Insecure-Requests","1");
            myRequest.Headers.Add("Accept-Language","sk,cs;q=0.8,en-US;q=0.5,en;q=0.3");
            myRequest.Headers.Add("Upgrade-Insecure-Requests: 1");
            myRequest.KeepAlive = true;
            myRequest.Headers.Add("Cache-Control","max-age=0");
            myRequest.Proxy.Credentials = System.Net.CredentialCache.DefaultCredentials;
            myRequest.AutomaticDecompression = (DecompressionMethods.GZip | DecompressionMethods.Deflate);
 
            //Returns 403
            HttpWebResponse myHttpWebResponse = (HttpWebResponse)myRequest.GetResponse();

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)