Difference between revisions of "Wgetheader.cs"
From AdonaiMedrado.Pro.Br
(New page: <code lang="csharp"> using System; using System.IO; using System.Net; namespace wgetheader { class Program { public static void Main(string[] args) { if (args.Length < 2...) |
|||
Line 3: | Line 3: | ||
using System.IO; | using System.IO; | ||
using System.Net; | using System.Net; | ||
+ | using System.Data; | ||
namespace wgetheader | namespace wgetheader | ||
Line 8: | Line 9: | ||
class Program | class Program | ||
{ | { | ||
− | + | public static void Main(string[] args) | |
− | + | { | |
− | + | if (args.Length < 2) | |
− | + | { | |
− | + | Console.WriteLine("Usage: wgethead url file"); | |
− | + | return; | |
− | + | } | |
try | try | ||
Line 34: | Line 35: | ||
buf = System.Text.ASCIIEncoding.Default.GetBytes(conteudo); | buf = System.Text.ASCIIEncoding.Default.GetBytes(conteudo); | ||
f.Write(buf,0,buf.Length); | f.Write(buf,0,buf.Length); | ||
+ | f.Close(); | ||
+ | f.Dispose(); | ||
} | } | ||
catch(Exception ex) | catch(Exception ex) |
Latest revision as of 23:24, 19 May 2009
using System; using System.IO; using System.Net; using System.Data; namespace wgetheader { class Program { public static void Main(string[] args) { if (args.Length < 2) { Console.WriteLine("Usage: wgethead url file"); return; } try { WebClient wc = new WebClient(); string conteudo = wc.DownloadString(args[0]); FileStream f = File.OpenWrite(args[1]); byte[] buf; foreach(string s in wc.ResponseHeaders.AllKeys) { buf = System.Text.ASCIIEncoding.Default.GetBytes( string.Format(">> {0} <<\n{1}\n{2}\n", s, wc.ResponseHeaders[s], new string('-',10))); f.Write(buf,0,buf.Length); } buf = System.Text.ASCIIEncoding.Default.GetBytes(conteudo); f.Write(buf,0,buf.Length); f.Close(); f.Dispose(); } catch(Exception ex) { Console.Error.WriteLine(ex.Message); } } } }