Request in c#; how to get a web page content fast

This is a start-up information, when you try to made an program that should us the Internet. Of course, many domains are already covered, example using the web services, but you can still find places where to use separat web requests. What happens if you need to grab a image from the Internet, over http? Or a web page?

 

This problem is solved by this method:

       static Stream GetStream(string URL)
        {
            HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(URL);



            // Assign the response object of 'HttpWebRequest' to a 'HttpWebResponse' variable.
            HttpWebResponse myHttpWebResponse = (HttpWebResponse)myRequest.GetResponse();

            #region Encoding
            Encoding encode = Encoding.UTF8;
            try
            {
                encode = System.Text.Encoding.GetEncoding(myHttpWebResponse.CharacterSet);
            }
            catch { }
            #endregion


            Stream streamResponse = myHttpWebResponse.GetResponseStream();


            //myHttpWebResponse.Close();
            return streamResponse;//Return the page as an Stream
        }

 

It works, but sometime you will need cookies, or you have to use a proxy server or many thinck like this. A long time ago, I create a class for working with requests. It can be downloaded by here; the ideea is when you have to use the same code again and again, it has to be optimized. In this moment my code is not very optimized, I just do it and forget about it, probably because it works. In the future this will be a project for an CodeProject article codeproject.com, where a long time ago, I promise to my self to put more code there :) .

coninue


Posted by: admin
Posted on: 9/21/2009 at 12:29 AM
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (5) | Post RSSRSS comment feed

The proxy checking is working

In this week I will try to solve a important problem of my main website application: verifyng the proxy servers online, in the front of the user. In this way, you will check the proxy online, fast and without waiting from a desktop application or something that involves your resources, excepting the Internet.

The mchanism of checking is simple: the application is doing a request to a web page that contains an XML as response and you will get the result using the content of the xml response. You can check this page response, using your browser and placing there an transparent proxy (the simpliest way). Intuitive you will fnd the mechanism, but this will be also explained in an article here.

How much does it take to me to solve this new functionality? 1 hour and 30 minutes; includint the design. Why do I finish it in a week? Because We are living bad times, on limit. :(( this is it.

After this part works okay, I can start to work on optimizing this two sites (pan-internet.com and this blog). In the end!


Posted by: admin
Posted on: 9/20/2009 at 1:22 AM
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (4) | Post RSSRSS comment feed

Our Home

An interesting movie about our HOME, the Earth. Where are we coming, where ar we going? What will hapens with our single planet, that suport the life? This are some questions that this movie send to you. And somebody wait an action from you: the entire earh population, from human, to wolfs, from fishes to birds .... Will you act? I belive that 99% of us, will continue in the same way ou life, the luxury and the dependence of the luxury (our at least, the convenience of our strong car, our big house ...); somehow normall, everyone reply "why me".

Will you act in the future? YES, you will made a lot of  thincks to solve what you broke in this years. Maybe to many. And you will be disapointed by you, by your youth earth cosumation. You will try to re-build the current paradise ...

This is the descriptin of the movie, from Youtube:

We are living in exceptional times. Scientists tell us that we have 10 years to change the way we live, avert the depletion of natural resources and the catastrophic evolution of the Earth's climate.
The stakes are high for us and our children. Everyone should take part in the effort, and HOME has been conceived to take a message of mobilization out to every human being.
For this purpose, HOME needs to be free. A patron, the PPR Group, made this possible. EuropaCorp, the distributor, also pledged not to make any profit because Home is a non-profit film.
HOME has been made for you : share it! And act for the planet.

Official homepage: http://www.home-2009.com


Posted by: admin
Posted on: 9/19/2009 at 5:26 PM
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (1) | Post RSSRSS comment feed