代理需要在Windows窗体应用程序中进行身份验 [英] The proxy requires authentication in windows form application

查看:75
本文介绍了代理需要在Windows窗体应用程序中进行身份验的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





有谁知道如何在Windows 7和XP中设置系统范围的代理?

我在C#中有一个通过互联网使用网络服务的Windows窗体项目。

在我的系统中它可以正常工作。但在使用代理的另一个系统中,它无法连接到Web服务! Althogh此系统中的浏览器连接正确。



代理需要身份验证,因此每个需要访问互联网的浏览器都必须输入用户名和密码。这对浏览器来说很好,但是我的C#应用​​程序无法访问互联网。



我在我的项目的app.config中设置了这个代码:

Hi,

Does anyone know how I can set up a system wide proxy in Windows 7 and XP?
I have a windows form project in C# that uses web service via internet.
in my system it works correctly. But in another system with proxy it doesn't connect to web service! Althogh the browsers in this system connect correctly.

The proxy requires authentication so each browser that needs to access the internet must have the username and password entered into it. This is fine for browsers, but my C# application can't access the internet .

I set this code in app.config of my project:

<system.net>
    <defaultProxy useDefaultCredentials="true" />
  </system.net>





请帮助我。



please help me.

推荐答案

显然默认凭据无法通过代理...

你有两个o ptions:

1.添加一个通过模块元素进行身份验证的DLL: https://msdn.microsoft.com/en-us/library/6w93fssz(v = vs.110).aspx [ ^ ] ... DLL必须包含一个实现 IWebProxy [ ^ ]



2.从您的代码中执行所有代理:

Obviously default credentials can't go through the proxy...
You have two options:
1. Add a DLL that does the authentication via module element: https://msdn.microsoft.com/en-us/library/6w93fssz(v=vs.110).aspx[^]...The DLL must contain a class implementing IWebProxy[^]

2. Do all the proxy from your code:
WebProxy oWebProxy = new WebProxy("proxy-server-address", true);
oWebProxy.Credientials = new NetworkCredential("user-name", "password");

WebRequest oWebRequest = WebRequest.Create("address");
oWebRequest.Proxy = oWebProxy;

// do the rest of the request...


这个解决方案非常棒:



http://stackoverflow.com/questions/186800/is-it-possible-to-specify-proxy -credentials-in-your-web-config [ ^ ]
This solution is realy great :

http://stackoverflow.com/questions/186800/is-it-possible-to-specify-proxy-credentials-in-your-web-config[^]


这篇关于代理需要在Windows窗体应用程序中进行身份验的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆