首页 > 其他 > 详细

模拟浏览器加载静态资源

时间:2020-04-15 22:34:12      阅读:61      评论:0      收藏:0      [点我收藏+]

模拟浏览器访问静态资源

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);
}
}
}
}

模拟浏览器加载静态资源

原文:https://www.cnblogs.com/chenligeng/p/12708892.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!