Click here to Skip to main content
15,868,009 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello guys!

I'm having some difficulties working on a light proxy server:
Working on Microsoft's C# example of WebRequest class, I get my code pinned under an instruction.

The code is:
HttpWebRequest request = (HttpWebRequest) WebRequest.Create("http://www.textfixer.com");

                request.Credentials = CredentialCache.DefaultCredentials;
                request.UserAgent = "Proxy Example";
               
                // get the response and write the status:
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                Console.WriteLine(response.StatusDescription);

                //Get the stream containing content returned by the server
                Stream dataStream = response.GetResponseStream();

                //Open the stream using a StreamReader for easy access
                StreamReader reader = new StreamReader(dataStream);

                //Read the content
                string responseFromServer = reader.ReadToEnd();

                //Display the content
                Console.WriteLine(responseFromServer);


The console doesn`t display anything, the browser "waits for response". If I stop the execution, the program is waiting on the line
HttpWebResponse response = (HttpWebResponse)request.GetResponse();

I have disabled the firewall and I am running on Win7 as administrator (though I doubt this matters).

I have tried using the Timeout property of the request. After the set timeout, it gets out of the instruction with an exception. So I guess there is no response...

Any insights?
Thanks a lot!

Shpid3r
Posted
Updated 9-Jan-11 7:40am
v3

Could be one of many things. The last time I tried this, I needed to set the credentials to get past my corporate firewall:
request.Credentials = CredentialCache.DefaultCredentials; 


There is a code sample on MSDN[^] I found very helpful.

If you are working on a proxy server, you might consider async methods, but I'd get this working first!
Hope this helps.
 
Share this answer
 
Comments
Dalek Dave 9-Jan-11 14:35pm    
Good Call.
I Checked your code in my System it works Fine. :)
also checked with others args and it works fine with these also

shpid3r wrote:
HttpWebResponse response = (HttpWebResponse)request.GetResponse();

I test it doesn't display anything when Internet-connection isn't available. it waits for Response from Internet Resource because of GetResponse().
please check your Connection while running this application.
and for more details please navigate This link[^]
 
Share this answer
 
v4
Thanks for your interest!
I think this is the moment I will sound silly but...

I am trying to build a proxy. The application I am working on is a process that will run on a machine. It accepts incoming connections on a port (3125 in this case) and should relay the request and response.

I run the program (developing and debunging) on the same machine I`m working on (connected to the internet). To debug it, I was setting my machine's proxy settings to 127.0.0.1:3125 and then tyring a web page in a browser.

I thought the browser would proxy through my application, which would go directly on the web (I didn`t imagine that my application will access itself through Windows' proxy settings).

I have changed the testing setup: I use a different PC to connect through my proxy. Things go alright now.

Thanks for testing the internet connection. I feel silly :-\
Shpid3r
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900