我创建了一个小型 Web 服务,它使用代理创建HttpWebRequest
到另一个网站,在我使用代理后我得到了那个错误:
请求“System.Net.WebPermission, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089”类型的权限失败。
我不知道如何解决它。
这是我的代码,
HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://website.com");
req.CookieContainer = c;
req.Proxy = new WebProxy("IP:PORT");
req.UserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; GTB7.4; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; InfoPath.2)";
req.Accept = "application/x-ms-application, image/jpeg, application/xaml+xml, image/gif, image/pjpeg, application/x-ms-xbap, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*";
req.Headers.Add("Accept-Language", "en-US");
req.ServicePoint.Expect100Continue = false;
req.AllowAutoRedirect = false;
req.Timeout = 10000;
req.Method = "GET";
req.KeepAlive = true;
req.ProtocolVersion = HttpVersion.Version10;