我想查找没有 HTTP 标头和数据传输速率的 HTML 文件的大小。以下是我的代码;
import java.net.*;
import java.io.*;
public class HttpCon
{
public static void main ( String[] args ) throws IOException
{
Socket s = null;
try
{
String host = "host1";
String file = "file1";
int port = 80;
s = new Socket(host, port);
OutputStream out = s.getOutputStream();
PrintWriter outw = new PrintWriter(out, false);
outw.print("GET " + file + " HTTP/1.1\r\n");
outw.print("Host: " + host + ":" + port + "\r\n");
outw.print("Accept: text/plain, text/html, text/*\r\n");
outw.print("\r\n");
outw.flush();
InputStream in = s.getInputStream();
InputStreamReader inr = new InputStreamReader(in);
BufferedReader br = new BufferedReader(inr);
String line;
while ((line = br.readLine()) != null)
{
System.out.println(line);
}
br.close();
}
}
}
但我不知道如何做到这一点。是否有我可以查看的源代码或我可以应用的任何资源?
任何帮助将不胜感激,在此先感谢。