我尝试使用套接字连接到 www.google.com,但结果是:
HTTP/1.0 302 找到
位置:http
://www.google.com.ph/
缓存控制:私有
内容类型:文本/html;字符集=UTF-8
这是我的Java测试代码:
Socket sock = new Socket();
try {
sock.connect(new InetSocketAddress("www.google.com", 80));
InputStream in = sock.getInputStream();
OutputStream out = sock.getOutputStream();
out.write(new String("GET /\r\n").getBytes());
byte[] readBuffer = new byte[4096];
while(true) {
int readSize = in.read(readBuffer);
if(readSize < 1) break;
System.out.println(new String(readBuffer, 0, readSize));
}
sock.close();
} catch(Exception e) {
}
这有什么问题?顺便说一句,我只需要使用套接字来实现这一点。tnx