日期:2014-05-16 浏览次数:20933 次
string reqest = @"GET /index.html HTTP/1.1";
Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
client.Connect(new IPEndPoint(IPAddress.Parse("61.135.169.105"), 80));
client.Send(System.Text.Encoding.UTF8.GetBytes(reqest));
byte[] data = new byte[655350];
int length = client.Receive(data);
Console.WriteLine(System.Text.Encoding.UTF8.GetString(data, 0, length));
Console.ReadLine();
public class MyWebRequest
{
public MyWebRequest(Uri uri)
{
this._RequestUri=uri;
this._Referer="";
this._UserAgent="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.1.4322)";
this._Cookie="";
this._AcceptType="*/*";
this._Method = "GET";
this._Timeout=15;
}
private void IniHeader()
{
this._Headers["Host"] = _RequestUri.Host;
if(this._Referer!="")
this._Headers["Referer"] = this.Referer;
if(this._UserAgent!="")
_Headers["User-Agent"] = this.UserAgent;
if(this._Cookie!="")
this._Headers["Cookie"] =this._Cookie;
this._Headers["Connection"] = "Keep-Alive";
}
public static MyWebRequest Create(string Url)
{
Uri uri=new Uri(Url);
return Create(uri);
}
public static MyWebRequest Create(Uri uri)
{
return new MyWebRequest(uri);
}
public MyWebResponse GetResponse()
{
this.IniHeader();
if(this._response == null
------解决方案--------------------
this._response.Socket == null
------解决方案--------------------
this._response.Socket.Connected == false)
{
this._response = new MyWebResponse();
this._response.Connect(this);
this._response.SetTime