Hi all, I have a real bugger of a problem that I just haven't been able to figure
out. I am working on writing my own proxy server in C# using TcpListener,
TcpClient, HttpWebRequest/Response and NetworkStream. I have everything
working pretty well except images won't load to their location.
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
The Rundown:
Run my proxy.exe file
Open up IE 7, point browser to www.google.com
Browser's GET request intercepted by the proxy
Proxy goes to google, returns initial page to browser
Browser sees that it needs to get two images
Sends these GET requests to proxy who sends them to appropriate google location
IE Browser screen knows the size and location of images, but they are not displayed
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
Command Line output:
C:\ProxyServer.exe
Waiting for a connection...
Browser Connected!
Received: GET http://www.google.com/ HTTP/1.0
Accept: */*
Accept-Language: en-us
UA-CPU: x86
Proxy-Connection: Keep-Alive
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322 ; .NET CLR 2.0.50727)
Host: www.google.com
Pragma: no-cache
Cookie: testcookie=;
*LENGTH: 339
*END RECEIVE from browser*
Connecting to Site: 'http://www.google.com/'
**FILE EXTENSION: 'com/'
RESPONSE LENGTH = -1
RESPONSE TYPE = text/html; charset=ISO-8859-1
STATUS CODE = OK
About to write to Browser
Browser Stream Written
Closed Connection
Browser Connected!
*GETTING NEXT ITEM
Received: GET http://www.google.com/intl/en_ALL/images/logo.gif HTTP/1.0
Accept: */*
Referer: http://www.google.com/
Accept-Language: en-us
UA-CPU: x86
Proxy-Connection: Keep-Alive
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322 ; .NET CLR 2.0.50727)
Pragma: no-cache
Host: www.google.com
Cookie: testcookie=;
*LENGTH: 399
*END RECEIVE from browser*
Connecting to Site: 'http://www.google.com/intl/en_ALL/images/logo.gif'
**FILE EXTENSION: 'gif'
RESPONSE LENGTH = 8558
RESPONSE TYPE = image/gif
STATUS CODE = OK
About to write to Browser
Browser Stream Written
Closed Connection
Browser Connected!
*GETTING NEXT ITEM
Received: GET http://www.google.com/images/nav_logo3.png HTTP/1.0
Accept: */*
Referer: http://www.google.com/
Accept-Language: en-us
UA-CPU: x86
Proxy-Connection: Keep-Alive
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322 ; .NET CLR 2.0.50727)
Pragma: no-cache
Host: www.google.com
Cookie: testcookie=;
*LENGTH: 392
*END RECEIVE from browser*
Connecting to Site: 'http://www.google.com/images/nav_logo3.png'
**FILE EXTENSION: 'png'
RESPONSE LENGTH = 6336
RESPONSE TYPE = image/png
STATUS CODE = OK
About to write to Browser
Browser Stream Written
Closed Connection
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
Where the output says Browser Stream written, that printout is after my NetworkStream.write()
to the browser client.
The RESPONSE LENGTH printouts are the actual size in bytes if I download
these images from a different browser not using a proxy. So I am getting the
correct response size, whereas with the plain html pages I was getting
RESPONSE LENGTH = -1 yet they were printed to my IE browser
(that code means that it doesn't know the exact size of the item)
I know this is so winded, I just like to be precise upfront. If anyone knows
anything about why this is a problem, I'd greatly appreciate any help.
I think it has something to do with string / image / byte arrays but have gone
down what it seems like every avenue with regard to it so...
Any help at all is greatly appreciated. If you have any questions or would like to
see source just let me know.
Thanks a bunch
Nick