Get remote site’s Response server-side

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(""); // 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!

Lascia un commento

Il tuo indirizzo email non sarà pubblicato.