不会吧我这样就可以
TcpClient tcpClient = new TcpClient("www.jsu.edu.cn", 8080); NetworkStream netStream = tcpClient.GetStream(); if (netStream.CanWrite)
{
Byte[] sendBytes = Encoding.UTF8.GetBytes("GET http://www.jsu.edu.cn/ HTTP/1.0\nAccept: */*\nAccept-Language: zh-cn\nUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; QQDownload 1.7; WPS)\nHost: www.jsu.edu.cn\nConnection: Keep-Alive\n\n");
netStream.Write(sendBytes, 0, sendBytes.Length);
}
else
{
Console.WriteLine("You cannot write data to this stream.");
tcpClient.Close();
netStream.Close();
return;
} if (netStream.CanRead)
{
byte[] bytes = new byte[tcpClient.ReceiveBufferSize]; netStream.Read(bytes, 0, (int)tcpClient.ReceiveBufferSize); string returndata = Encoding.UTF8.GetString(bytes); Console.WriteLine("This is what the host returned to you: " + returndata);
}
else
{
Console.WriteLine("You cannot read data from this stream.");
tcpClient.Close();
netStream.Close();
return;
}
netStream.Close();
TcpClient tcpClient = new TcpClient("www.jsu.edu.cn", 8080); NetworkStream netStream = tcpClient.GetStream(); if (netStream.CanWrite)
{
Byte[] sendBytes = Encoding.UTF8.GetBytes("GET http://www.jsu.edu.cn/ HTTP/1.0\nAccept: */*\nAccept-Language: zh-cn\nUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; QQDownload 1.7; WPS)\nHost: www.jsu.edu.cn\nConnection: Keep-Alive\n\n");
netStream.Write(sendBytes, 0, sendBytes.Length);
}
else
{
Console.WriteLine("You cannot write data to this stream.");
tcpClient.Close();
netStream.Close();
return;
} if (netStream.CanRead)
{
byte[] bytes = new byte[tcpClient.ReceiveBufferSize]; netStream.Read(bytes, 0, (int)tcpClient.ReceiveBufferSize); string returndata = Encoding.UTF8.GetString(bytes); Console.WriteLine("This is what the host returned to you: " + returndata);
}
else
{
Console.WriteLine("You cannot read data from this stream.");
tcpClient.Close();
netStream.Close();
return;
}
netStream.Close();
解决方案 »
- 关于将数据库的地点信息导入xml里然后生成树的问题
- 怎么获取用C++写好了的ocx控件的接口!
- 求一个正则表达式
- 请教一个从网页获取数据的问题
- 如何让datagrid直接显示某个表的数据而不显示一个“+”号
- C#中listBox控件与sql Server数据库应该怎么连接啊?使用listBox的dataSource属性吗?
- 如何屏蔽Media Player 的双击全屏事件?
- 怎么能生成指定位数的随机数呀
- 怎样实现这样的一个查询?100分!
- 一个关于委托的问题!要分就来!(等来拿!)
- 请问在winform中如何让listview控件在detail视图下的第一列显示一个小图标呢??
- 怎么样保存把网页上的图片保存为指定大小?
GET / HTTP/1.0
直接这样就行了,还有HTTP1.0可以不需要HOST字段,对于1.0版本的,Connection也没有多大意义,1.0的好像总是一发送完成就关闭的。
估计可能是你的 GET 这里错了吧
char buf[DEFAULT_LEN+1] = "GET / HTTP/1.0\r\n"
"Accept: */*\r\n"
"Accept-Language: zh-cn\r\n"
"User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; QQDownload 1.7; WPS)\r\n"
"Host: www.jsu.edu.cn\r\n"
"Connection: Keep-Alive\r\n"
"\r\n";
注意 GET里面,是相对URI
不是绝对的URL