The requested resource (/HTTP/1.1) is not available

linxinyidian 2011-03-19 07:44:55
编了个访问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,不知什么原因产生此异常……


...全文
11699 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
Cary_诚 2011-10-12
  • 打赏
  • 举报
回复
pw.println("GET /HTTP/1.1 ");
第一个斜杠后面有个空格,写成pw.println("GET / HTTP/1.1 ");
不然会链接到127.0.0.1:8080/HTTP/1.1

81,110

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧