post icon

Get remote site’s Response server-side

Recuperare la Response di un sito remoto lato server

E’ possibile ottenere lato-server il contenuto della Response di un sito remoto utilizzando la classe HttpWebRequest del namespace System.Net.

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.google.it"); // Set some reasonable limits on resources used by this request request.MaximumAutomaticRedirections = 3; request.MaximumResponseHeadersLength = 5; // Set credentials to use for this request. request.Credentials = CredentialCache.DefaultCredentials; HttpWebResponse response = (HttpWebResponse)request.GetResponse(); // Get the stream associated with the response. Stream receiveStream = response.GetResponseStream (); // Pipes the stream to a higher level stream reader with the required encoding format. StreamReader readStream = new StreamReader (receiveStream, Encoding.UTF8); Response.Write (readStream.ReadToEnd ()); response.Close (); readStream.Close ();

Enjoy snippet!

28 febbraio 2010 @ 15:56

No comments yet.

Leave a comment

Leave a Reply

Are you human? Time limit is exhausted. Please reload CAPTCHA.