Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/316.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# System.Net.WebException:远程服务器返回错误:(403)禁止_C#_Proxy_System.net.httpwebrequest - Fatal编程技术网

C# System.Net.WebException:远程服务器返回错误:(403)禁止

C# System.Net.WebException:远程服务器返回错误:(403)禁止,c#,proxy,system.net.httpwebrequest,C#,Proxy,System.net.httpwebrequest,当我在公司防火墙后面,使用C#与我接收到的网站进行交互时 System.Net.WebException : The remote server returned an error: (403) Forbidden. 但是,我可以在同一台计算机上打开Internet Explorer,并且访问同一个网站时没有问题。此外,我可以切换到我公司的“非防火墙”客户网络,我再次表示,使用我的C#应用程序访问同一网站没有问题 我在其他stackoverflow帖子中读到,要通过代理进行访问,我需要在我的

当我在公司防火墙后面,使用C#与我接收到的网站进行交互时

System.Net.WebException : The remote server returned an error: (403) Forbidden. 
但是,我可以在同一台计算机上打开Internet Explorer,并且访问同一个网站时没有问题。此外,我可以切换到我公司的“非防火墙”客户网络,我再次表示,使用我的C#应用程序访问同一网站没有问题

我在其他stackoverflow帖子中读到,要通过代理进行访问,我需要在我的项目的app.config中包含以下内容:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.net>
    <defaultProxy useDefaultCredentials="true" />
  </system.net>
</configuration>
…还有更多的代码来处理对帖子的回复;但我没有包括它,因为它似乎与解决代理问题无关

我对这个话题几乎是个新手。直观地看,我应该能够利用InternetExplorers代理设置,这样我的C#应用程序也可以使用它们


让我更加困惑的是,我注意到InternetExplorer并没有使用单一的代理服务器,而是在执行一个自动配置脚本。此脚本有许多“if”语句,根据所需的ip地址检查要使用的代理ip

解决方案是为请求设置代理。在我的例子中,我打开配置脚本并跟踪“If”语句以查找Internet Explorer正在使用的代理,然后将url和端口复制/粘贴到下面显示的字段中

    var request = (HttpWebRequest)WebRequest.Create(loginUrl);
    WebProxy myproxy = new WebProxy(@"YOUR_PROXY_URL", YOUR_PROXY_PORT) { BypassProxyOnLocal = false };
    request.Proxy = myproxy;
    request.ProtocolVersion = HttpVersion.Version10;

解决方案是为请求设置代理。在我的例子中,我打开配置脚本并跟踪“If”语句以查找Internet Explorer正在使用的代理,然后将url和端口复制/粘贴到下面显示的字段中

    var request = (HttpWebRequest)WebRequest.Create(loginUrl);
    WebProxy myproxy = new WebProxy(@"YOUR_PROXY_URL", YOUR_PROXY_PORT) { BypassProxyOnLocal = false };
    request.Proxy = myproxy;
    request.ProtocolVersion = HttpVersion.Version10;