It's very simple example. but...
Code:using System; using System.Collections.Generic; using System.Windows.Forms; static class Program { /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1());//here!!!!!! TestURL T = new TestURL(); T.download(); } }Code:using System; class TestURL { public void download() { CSDownloadURL web = new CSDownloadURL(); string strOut; web.setURL1("http://www.google.com"); web.DownloadURL(out strOut); Console.WriteLine(strOut); } }Thanks for your helpCode:using System; using System.Text; using System.IO; using System.Net; public class CSDownloadURL { private string m_strURL; public void setURL1(string strURL) { m_strURL = strURL; } public void DownloadURL(out string strContents) { WebRequest req = WebRequest.Create(m_strURL); WebResponse res = req.GetResponse(); int iTotalBuff = 0; Byte[] Buffer = new Byte[128]; Stream stream = res.GetResponseStream(); iTotalBuff = stream.Read(Buffer, 0, 128); StringBuilder strRes = new StringBuilder(""); while (iTotalBuff != 0) { strRes.Append(Encoding.ASCII.GetString(Buffer, 0, iTotalBuff)); iTotalBuff = stream.Read(Buffer, 0, 128); } strContents = strRes.ToString(); } }


Reply With Quote