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