0

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.

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#

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.

My proxy server code is very similar to the one here: Simple Http proxy using Sockets: Questions

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.

Community
  • 1
  • 1
Shankar
  • 1,634
  • 1
  • 18
  • 23
  • Stepping back a bit, rather than trying to write a proxy server yourself (which requires thousands of lines of code and needs more than 1 thread), why not just use FiddlerCore? (http://fiddler2.com/core) – EricLaw Aug 17 '12 at 20:55
  • thanks Eric. i did consider fiddler core, but looking at the help file, i find that fiddler has lot more features than what i require. all i need to do is to inspect an httprequest for certain conditions and if it is met, i let it through, if not, i abort. i'll finish my app with fiddlercore first, and then come back to this problem. but if you can point me to reliable wininet proxy setting code, that would be great. and thanks for the fiddlercore, its a great piece of software. – Shankar Aug 17 '12 at 21:04
  • In order to inspect "a HTTP request", you have to be able to determine where the request begins and ends, which means you have to have a full knowledge of the HTTP protocol, including chunked encoding, MIME, keep-alive connections, etc. And if you want to examine HTTPS traffic, you need dozens of other technologies. – EricLaw Aug 17 '12 at 21:06

1 Answers1

0

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.

EricLaw
  • 56,563
  • 7
  • 151
  • 196
  • yes, i got that code as well, but couldn't get my app to work. this most likely means i'm doing something wrong or something is wrong with the internet settings on my dev box. i'll use fiddlercore for now and get back to you. thanks. – Shankar Aug 17 '12 at 21:11