home *** CD-ROM | disk | FTP | other *** search
- using System;
- using System.Net;
- using System.Text;
- using System.IO;
- using System.Globalization;
-
- class HttpGet
- {
- static void GetPage(String url)
- {
- int BufferSize = 1024;
- WebRequest Request;
- WebResponse Response;
- Stream RespStream;
- byte [] Buffer;
- int BytesRead;
-
- /* -- uncommment this code and replace "httpproxy" with the name of your
- -- http proxy server
-
- String defaultProxyName = "httpproxy";
- int defaultProxyPort = 80;
-
- // create a new Object with the Proxy Information that
- // you wish to use
-
- DefaultControlObject proxyObject = new DefaultControlObject(defaultProxyName, defaultProxyPort);
-
- // Disable Proxy use when the host is local i.e. without periods.
- proxyObject.ProxyNoLocal = true;
-
- // Now actually take over the global with our new settings, all new requests
- // use this proxy info
-
- GlobalProxySelection.Select = proxyObject;
- */
-
- Request = WebRequestFactory.Create(url);
-
- Response = Request.GetResponse();
-
- Console.WriteLine("Status code: " + Response.Status.ToString());
-
- RespStream = Response.GetResponseStream();
-
- BufferSize = (int)Response.ContentLength;
-
- Console.WriteLine("Entity body:");
-
- Buffer = new byte[BufferSize];
-
- BytesRead = RespStream.Read(Buffer, 0, BufferSize);
-
- while (BytesRead != 0)
- {
- String content = Encoding.ASCII.GetString(Buffer, 0, BytesRead);
- Console.Write(content);
-
- BytesRead = RespStream.Read(Buffer, 0, BufferSize);
-
- }
- }
-
- public static String url;
-
- public static void Main(string[] Args)
- {
- int ret = Initialize(Args);
-
- if (0 == ret)
- GetPage(url);
- }
-
- public static int Initialize(String[] args)
- {
- if (args.Length == 0)
- {
- Usage();
- return -1;
- }
-
-
- for (int i=0;i<args.Length;i++)
- {
- if (
- String.Compare(args[i],"HELP", true) == 0 ||
- String.Compare(args[i],"?", true) == 0 ||
- String.Compare(args[i],"/h", true) == 0 ||
- String.Compare(args[i],"-h", true) == 0 ||
- String.Compare(args[i],"-?", true) == 0 ||
- String.Compare(args[i],"/?", true) == 0
- )
- {
- Usage();
- return -1;
- }
-
- if (args[i].CompareTo("-url")==0)
- {
- url = args[i+1];
- }
- }
-
- return 0;
- }
-
- public static void Usage()
- {
- Console.WriteLine("Usage: httpget [-url http://...]\n");
- Console.WriteLine("Examples : httpget -url http://localhost/Trader/StockQuote.soap");
- }
- }
-