111,120
社区成员
发帖
与我相关
我的任务
分享
static void Main(string[] args)
{
string[] L = new string[6];
L[0] = "GET /index.html HTTP/1.1";
L[1] = "Host:www.baidu.com";
L[2] = "Accept:*/*";
L[3] = "User-Agent:Mozilla/4.0 (compatible; MSIE 5.00; Windows 98)";
L[4] = "Connection:Keep-Alive";
L[5] = "";
int tLength = 0;
for (int i = 0; i < 6; i++)
{
string s = L[i];
//s += "\r\n";
tLength += s.Length;
}
byte[] data = new byte[tLength + 2 * 6];
int currentPos = 0;
for (int i = 0; i < 6; i++)
{
string s = L[i];
for (int j = 0; j < s.Length; j++)
{
data[currentPos] = (byte)s[j];
currentPos++;
}
data[currentPos] = (byte)'\r';
currentPos++;
data[currentPos] = (byte)'\n';
currentPos++;
}
TcpClient tc = new TcpClient("www.baidu.com", 80);
tc.Client.Send(data);
byte[] page = new byte[1024];
tc.Client.Receive(page);
}