![]() |
从 TCP 连接中读取一行文本,不包含回车
strText = Socket.ReadLine
下面的代码创建一个 NetBox.Socket 对象,连接到 www.zydsoft.com 的 WEB 端口,发出一个请求后返回结果:
Set Socket = CreateObject("NetBox.Socket") Socket.Connect "www.zydsoft.com", 80 Socket.Timeout = 2000 Socket.WriteLine "GET /test.asp HTTP/1.0" Socket.WriteBlankLines 1 Do While Not Socket.Eof Shell.Console.WriteLine ": " & Socket.ReadLine Loop Socket.Close
这个代码的运行结果是:
: HTTP/1.1 404 File Not Found : Server: NetBox Version 2.01 Build 2544 : Connection: Close : Content-Type: text/html : Date: Wed, 13 Nov 2002 07:05:48 GMT : Content-Length: 101 : : <html><head><title>404 File Not Found</title></head> : <body><h1>404 File Not Found</h1></body></html>
哈,根本就没有这么个文件嘛,当然 404 了。