- private void showDir()throws Exception
- {
- ta.setText("");
- String url = tf.getText();//http://192.168.27.190:8080/myweb/demo.html
- int index1 = url.indexOf("//")+2;
- int index2 = url.indexOf("/",index1);
- String str = url.substring(index1,index2);
- String[] arr = str.split(":");
- String host = arr[0];
- int port = Integer.parseInt(arr[1]);
- String path = url.substring(index2);
- //ta.setText(str+".."+path);
- Socket s = new Socket(host,port);
- PrintWriter pw = new PrintWriter(s.getOutputStream(),true);
- pw.println("GET "+path);
- pw.println("Accept: text/html, application/xhtml+xml,*/*");
- pw.println("Accept-Language: zh-CN");
- pw.println("Host: "+host+":"+port);
- pw.println("Connection: closed");
- pw.println();
- pw.println();
- BufferedReader bufIn =
- new BufferedReader(new InputStreamReader(s.getInputStream()));
- String line = null;
- while ((line=bufIn.readLine())!=null)
- {
- ta.append(line+"\r\n");
- }
- s.close();
- }
复制代码
请问一下,毕老师做的那个GUI浏览器,访问自己的Tomcat服务器有那个消息头,为什么我自己也是一样做的,访问没有上面的消息,代码都一样
|
|