The requested resource (/HTTP/1.1) is not available
编了个访问Tomcat的小程序,
package TestHttp;
import java.io.BufferedReader;
import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;
import java.io.*;
public class Test {
public static void main(String[] args) throws UnknownHostException, IOException {
String ss;
Socket s = new Socket("127.0.0.1", 8080);
OutputStream os = s.getOutputStream();
PrintWriter pw = new PrintWriter(os);
pw.println("GET /HTTP/1.1 ");
pw.println("Host:localhost");
pw.println("Content-type: text ml");
pw.println();
pw.flush();
BufferedReader bf = new BufferedReader(new InputStreamReader(s.getInputStream()));
while(( ss =bf.readLine())!=null) {
System.out.println(ss);
}
bf.close();
pw.close();
os.close();
s.close();
}
}
返回一些文本
<html><head><title>Apache Tomcat/7.0.11 - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 404 - /HTTP/1.1</h1><HR size="1" noshade="noshade"><p><b>type</b> Status report</p><p><b>message</b> <u>/HTTP/1.1</u></p><p><b>description</b> <u>The requested resource (/HTTP/1.1) is not available.</u></p><HR size="1" noshade="noshade"><h3>Apache Tomcat/7.0.11</h3></body></html>
转为html格式,显示为 HTTP 404 异常
The requested resource (/HTTP/1.1) is not available.
我用的是Tomcat 7.0,不知什么原因产生此异常……