问题描述
我正在运行Windows 7和IE9.我正在写一个Winforms应用程序(.net 4.0& c#),该应用程序在另一个线程上运行代理服务器(使用TcpListener).
I'm running windows 7 and IE9. I'm writing a winforms application (.net 4.0 & c#) that runs a proxy server (using TcpListener) on another thread.
在实例化主要表单之前,我使用InternetSetOption设置了代理并启动了代理服务器.
Before I instantiate the main form i set the proxy using InternetSetOption and start the proxy server.
我的代理设置代码与以下代码非常相似:
My proxy setting code is very similar to the one here: Set Proxy UserName and Password using Wininet in C#
然后,我浏览到IE中的站点,IE无法连接到我的代理服务器.同样,IE工具-> Internet选项->连接->局域网设置->为您的局域网使用代理服务器复选框未选中.但是当我运行提琴手时,此复选框已选中.这意味着提琴手正确设置了代理,但我没有.提琴手是怎么做到的?我走遍了无数博客,InternetSetOption上的MSDN文章都是徒劳的.任何帮助表示赞赏.
then i browse to a site in IE, IE doesn't connect to my proxy server. also, IE tools --> internet options --> connection --> lan settings --> use a proxy server for your LAN checkbox is NOT checked. but when I run fiddler, this checkbox IS checked. this means fiddler is setting the proxy correctly, but I'm not. how does fiddler do that? i have gone thru' numerous blogs, MSDN articles on InternetSetOption in vain. any help is appreciated.
我的代理服务器代码与此处的代码非常相似:使用套接字的简单Http代理:问题
My proxy server code is very similar to the one here: Simple Http proxy using Sockets: Questions
我知道我的代理服务器有效,因为当我转到IE工具->互联网选项->连接->局域网设置并将代理服务器明确设置为127.0.0.1:9898时(即我在其中运行代理的位置)服务器),IE和所有其他浏览器都连接到我的服务器.
I know my proxy server works because, when I go to IE tools --> internet options --> connection --> lan settings and explicitly set the proxy server to 127.0.0.1:9898 (thats where I run my proxy server), IE and all other browsers connect to my server.
推荐答案
此代码下载中的WinINET.cs文件: http://code.msdn.microsoft.com/CSWebBrowserWithProxy-c8535715 具有设置WinINET代理的核心功能.它得到一些小细节,但有一些错误,但是在大多数情况下都可以正常使用.
The WinINET.cs file in this code download: http://code.msdn.microsoft.com/CSWebBrowserWithProxy-c8535715 has the core functionality to set the WinINET proxy. It gets a few minor details slightly wrong, but will work properly for most cases.
这篇关于无法从WinForms应用程序设置WinInet代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!