using System;
using System.Collections;
using System.Net;
using System.IO;
using System.Text;
class Response
{
public static void Main(String[] args)
{
int BUFFER_SIZE = 128;
if (args.Length != 1){
Console.WriteLine("Usage: Response URL");
return ;
}
try
{
WebRequest theRequest = (WebRequest) WebRequestFactory.Create(args[0]);
WebResponse theResponse = theRequest.GetResponse();
int BytesRead = 0;
Byte[] Buffer = new Byte[BUFFER_SIZE];
Console.WriteLine("---------------Content----------------------");
Stream ResponseStream = theResponse.GetResponseStream();
BytesRead = ResponseStream.Read(Buffer, 0, BUFFER_SIZE);
StringBuilder strResponse = new StringBuilder("");
while (BytesRead != 0 )
{
strResponse.Append(Encoding.ASCII.GetString(Buffer,0,BytesRead));
BytesRead = ResponseStream.Read(Buffer, 0, BUFFER_SIZE);
}
Console.WriteLine(strResponse.ToString());
Console.WriteLine("---------------Headers----------------------");
WebHeaders headers=theResponse.Headers;
foreach(string header in headers.AllKeys){
Console.WriteLine(header + "{");
foreach(string value in headers.GetValues(header)){
Console.WriteLine(value);
}
Console.WriteLine("}");
}
Console.WriteLine("---------------ContentLength----------------");
Console.WriteLine(theResponse.ContentLength );
Console.WriteLine("---------------ContentType------------------");
Console.WriteLine(theResponse.ContentType );
Console.WriteLine("---------------ContentLength----------------");
Console.WriteLine(theResponse.ContentLength );
Console.WriteLine("---------------Status-----------------------");
Console.WriteLine(theResponse.Status );
Console.WriteLine("---------------StatusDescription------------");
Console.WriteLine(theResponse.StatusDescription );
Console.WriteLine("--------------------------------------------");
}
catch (Exception e)
{
Console.WriteLine(e);
return;
}
}
}
编译方法
csc /r:System.Net.dll /r:System.dll Response.cs
执行方法
response http://www.sina.com.cn
注:这是我用来调试程序用的小程序,我想去别的网站抓东西也是类似的,取回来的内容编个程序分析一下,加到自己网站上也不是什么难事。
这个程序能打出来session cookie等等内容,这才是我编这个程序的目的。
重粒子@++2K0205

