c# - C# HttpWebRequest 返回错误 403。如何从 C# 中的 HttpWebRequest 修复 403 错误
问题描述
我一直在尝试在网站上使用 a ,但在我尝试访问的特定网站上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();
解决方案
推荐阅读
- idris - %inline 对 Idris 的真正作用是什么?以及何时使用它?
- javascript - 粘性/固定导航栏,滚动时 BG 透明到实体(无引导程序)
- c - 使用 C 在 Gtk 中创建小部件列表
- firebase - 如何永远不会在 Firebase 托管的网络应用程序上通过谷歌登录退出?
- c# - 如何基于 Entity Framework Core 数据库中的另一个表创建计算列-first
- java - 我想在 mainactivity java 类中使用片段 UI 元素 id 来完成 mainactivity 类而不是片段类上的单击侦听器事件
- python - 将给定数组拆分为 k 个子数组,使得所有子数组的最大和最小
- c++ - 仅从文件中读取特定数据...如果传递字符串值,则从文件c ++ 98中读取所有内容
- css - 如何将切换的 DIV 粘贴到切换导航栏的顶部
- javascript - 基于另一个数组连接一个数组的项