模拟浏览器加载静态资源
模拟浏览器访问静态资源
public static void main(String[] args) throws Exception{
ServerSocket sc = new ServerSocket(8089);
while (true) {
Socket accept = sc.accept();
BufferedReader bf = new BufferedReader(new InputStreamReader(accept.getInputStream()));
String s = bf.readLine();
String[] s1 = s.split(" ");
String name = s1[1];
File file = new File("F:/car" + name);
System.out.println(name);
if (file.exists()) {
FileInputStream fis = new FileInputStream("F:/car" + name);
OutputStream outputStream = accept.getOutputStream();
outputStream.write("HTTP/1.1 200 OK\r\nContent-Type:image/jpeg\r\n\r\n".getBytes());
byte[] b = new byte[1024];
int len;
while ((len = fis.read(b)) != -1) {
outputStream.write(b, 0, len);
}
}
}
}