neral

neral

  • NA
  • 1
  • 0

get source code

Aug 28 2004 11:53 AM
Hi, i want to get the source code from [URL]http://www.google.de[/URL] but the sreen is changing in black... why? is the method auslesen() wrong? [PHP] using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; //Zum Auslesen der Seite using System.Net; using System.IO; using System.Text; namespace WebApplication4 { public class WebForm1 : System.Web.UI.Page { protected System.Web.UI.WebControls.TextBox TextBox1; protected System.Web.UI.WebControls.Button Button1; protected System.Web.UI.WebControls.Label Label1; protected System.Web.UI.WebControls.Label Label3; protected System.Web.UI.WebControls.Label Label2; private void Page_Load(object sender, System.EventArgs e) { string texturl = TextBox1.Text; } #region Vom Web Form-Designer generierter Code override protected void OnInit(EventArgs e) { // // CODEGEN: Dieser Aufruf ist für den ASP.NET Web Form-Designer erforderlich. // InitializeComponent(); base.OnInit(e); } /// /// Erforderliche Methode für die Designerunterstützung. /// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden. /// private void InitializeComponent() { this.Button1.Click += new System.EventHandler(this.Button1_Click); this.Load += new System.EventHandler(this.Page_Load); } #endregion private void Button1_Click(object sender, System.EventArgs e) { Label1.Text = TextBox1.Text; Label3.Text = auslesen(); } public string auslesen() { string htmlcode = null; Uri url = new Uri(TextBox1.Text); //Creates an HttpWebRequest with the specified URL. HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url); // Sends the HttpWebRequest and waits for the response. HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse(); // Gets the stream associated with the response. Stream receiveStream = myHttpWebResponse.GetResponseStream(); Encoding encode = System.Text.Encoding.GetEncoding("utf-8"); // Pipes the stream to a higher level stream reader with the required encoding format. StreamReader readStream = new StreamReader( receiveStream, encode ); //Console.WriteLine("\r\nResponse stream received."); Char[] read = new Char[256]; // Reads 256 characters at a time. int count = readStream.Read( read, 0, 256 ); //Console.WriteLine("HTML...\r\n"); while (count > 0) { // Dumps the 256 characters on a string and displays the string to the console. String str = new String(read, 0, count); htmlcode = htmlcode + str; count = readStream.Read(read, 0, 256); } // Console.WriteLine(""); // Console.ReadLine(); // Releases the resources of the response. myHttpWebResponse.Close(); // Releases the resources of the Stream. readStream.Close(); return htmlcode; } } } [/PHP] the method auslesen() witch works! but the first dont work :\ [PHP] using System; using System.Net; using System.IO; using System.Text; namespace ConsoleApplication5 { class Class1 { static void Main(string[] args) { Uri url = new Uri("http://www.google.de"); //Creates an HttpWebRequest with the specified URL. HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url); // Sends the HttpWebRequest and waits for the response. HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse(); // Gets the stream associated with the response. Stream receiveStream = myHttpWebResponse.GetResponseStream(); Encoding encode = System.Text.Encoding.GetEncoding("utf-8"); // Pipes the stream to a higher level stream reader with the required encoding format. StreamReader readStream = new StreamReader( receiveStream, encode ); Console.WriteLine("\r\nResponse stream received."); Char[] read = new Char[256]; // Reads 256 characters at a time. int count = readStream.Read( read, 0, 256 ); Console.WriteLine("HTML...\r\n"); while (count > 0) { // Dumps the 256 characters on a string and displays the string to the console. String str = new String(read, 0, count); Console.Write(str); count = readStream.Read(read, 0, 256); } Console.WriteLine(""); // Releases the resources of the response. myHttpWebResponse.Close(); // Releases the resources of the Stream. readStream.Close(); } } } [/PHP] greetz neral