socket如何实现请求***.***.com/1.html这样的页面?
IPHostEntry ipHostInfo = Dns.GetHostEntry(host);
IPAddress ipAddress = ipHostInfo.AddressList[0];
IPEndPoint remoteEP = new IPEndPoint(ipAddress, port);
// Create a TCP/IP socket.
Socket client = new Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp);
// Connect to the remote endpoint.
client.BeginConnect(remoteEP,
new AsyncCallback(ConnectCallback), client);
connectDone.WaitOne();
// Send test data to the remote device.
string request = "GET / HTTP/1.1\r\nHost: " + client +
"\r\nConnection: Close\r\n\r\n ";
//Byte[] bytesSent = Encoding.ASCII.GetBytes(request);
Send(client, request);
sendDone.WaitOne();
我有这么一段代码,其中当host为www.***.com这样的参数时,能够请求到这样的页面,当host为***.***.com/1.html这样的页面时,IPHostEntry ipHostInfo = Dns.GetHostEntry(host);就会抛出不知道这样的主机的异常,请问如何利用socket实现请求这样的的页面?
万分感谢啊!!
小弟在csdn的第一个问题。
------解决方案--------------------string request = "GET / HTTP/1.1\r\nHost: " + client +
"\r\nConnection: Close\r\n\r\n ";
这个是你自己写的还是抄的?如果是后者,你要翻阅HTTP协议方面的书籍。