日期:2014-05-20  浏览次数:20985 次

IPEndPoint,如何对虚拟主机取得节点?
我用自己构造的HTTP消息头请求网页,当目标网页所在服务器是独立IP时,可用,一旦换成虚拟主机,就是404错误。请问如何让IPEndPoint对虚拟主机也可用?
【code】
//构造最简消息头文件
string   sendstr   =   null;
sendstr   +=   "GET   http://www.abc.com   HTTP/1.1\r\n ";
sendstr   +=   "Host:   www.abc.com\r\n\r\n ";
//构造IP及PORT
byte[]   sendStr   =   new   byte[sendstr.Length   +   1];
sendStr   =   Encoding.ASCII.GetBytes(sendstr);
IPAddress   ip   =   Dns.GetHostEntry( "www.amxv.com ").AddressList[0];
IPEndPoint   ipep   =   new   IPEndPoint(ip,80);
//启用SOCKET
Socket   sock   =   new   Socket(AddressFamily.InterNetwork,   SocketType.Stream,   ProtocolType.Tcp);
sock.Connect(ipep);
//接受BYTE,并转为STRING
Byte[]   RecvBytes   =   new   Byte[256];
int   bytes   =   sock.Receive(RecvBytes,   RecvBytes.Length,   0);
MessageBox.Show( "bytes: "+bytes);
String   strRetPage   =   Encoding.ASCII.GetString(RecvBytes,   0,   bytes);
//显示接收到的源代码
MessageBox.Show(strRetPage);
//关闭SOCKET
sock.Shutdown(SocketShutdown.Both);
sock.Close();




------解决方案--------------------
顶!