你的程序没有问题,用其他网址试都是正确的。(http://www.apache.org/index.html)
我这里 http://us01.xmlsearch.findwhat.com/ 这个网址都打不开,应该是你的程序无法
与us01.xmlsearch.findwhat.com的80端口建立连接。
============================================================================
/*
* Created on 2004-11-12
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package http;import java.net.*;
import java.io.*;public class TestSocket { public static void main(String argv[]) throws Exception {
new TestSocket().get(); } public void get() throws Exception {
final int HTTP_PORT = 80;
InetAddress address = InetAddress
.getByName("www.apache.org");
Socket socket = new Socket(address, HTTP_PORT);
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(socket
.getOutputStream()));
BufferedReader in = new BufferedReader(new InputStreamReader(socket
.getInputStream()));
String httpGet="GET http://www.apache.org/index.html HTTP/1.0\r\n"
+ "Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*\r\n"
+ "User-Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows 98)\r\n"
+ "Host: www.apache.org\r\n\r\n";
out.write(httpGet);
out.flush(); String line;
//StringBuffer sb = new StringBuffer();
while ((line = in.readLine()) != null) {
//sb.append(line);
System.out.println(line);
}
out.close();
in.close();
socket.close();
//System.out.println(sb.toString());
}}==============================================================返回内容:HTTP/1.1 200 OK
Date: Fri, 12 Nov 2004 11:00:25 GMT
Server: Apache/2.0.52 (Unix)
Last-Modified: Mon, 18 Oct 2004 00:38:27 GMT
ETag: "2da7cde-2e53-feb2e6c0"
Accept-Ranges: bytes
Content-Length: 11859
Cache-Control: max-age=86400
Expires: Sat, 13 Nov 2004 11:00:25 GMT
Connection: close
Content-Type: text/html; charset=ISO-8859-1<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!--
Copyright 1999-2004 The Apache Software Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<html>
<head>
。
我这里 http://us01.xmlsearch.findwhat.com/ 这个网址都打不开,应该是你的程序无法
与us01.xmlsearch.findwhat.com的80端口建立连接。
============================================================================
/*
* Created on 2004-11-12
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package http;import java.net.*;
import java.io.*;public class TestSocket { public static void main(String argv[]) throws Exception {
new TestSocket().get(); } public void get() throws Exception {
final int HTTP_PORT = 80;
InetAddress address = InetAddress
.getByName("www.apache.org");
Socket socket = new Socket(address, HTTP_PORT);
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(socket
.getOutputStream()));
BufferedReader in = new BufferedReader(new InputStreamReader(socket
.getInputStream()));
String httpGet="GET http://www.apache.org/index.html HTTP/1.0\r\n"
+ "Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*\r\n"
+ "User-Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows 98)\r\n"
+ "Host: www.apache.org\r\n\r\n";
out.write(httpGet);
out.flush(); String line;
//StringBuffer sb = new StringBuffer();
while ((line = in.readLine()) != null) {
//sb.append(line);
System.out.println(line);
}
out.close();
in.close();
socket.close();
//System.out.println(sb.toString());
}}==============================================================返回内容:HTTP/1.1 200 OK
Date: Fri, 12 Nov 2004 11:00:25 GMT
Server: Apache/2.0.52 (Unix)
Last-Modified: Mon, 18 Oct 2004 00:38:27 GMT
ETag: "2da7cde-2e53-feb2e6c0"
Accept-Ranges: bytes
Content-Length: 11859
Cache-Control: max-age=86400
Expires: Sat, 13 Nov 2004 11:00:25 GMT
Connection: close
Content-Type: text/html; charset=ISO-8859-1<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!--
Copyright 1999-2004 The Apache Software Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<html>
<head>
。
解决方案 »
- /etc/inittab设置启动tomcat导致web应用字符集为ANSI_X3.4-1968,为什么、怎么改为utf-8
- 电子商务网
- Java电信网管请教
- jsp操作数据库
- 怎么从一台服务器调用另外一台服务器的EJB?
- 关于tomcat 6.0 web.xml
- 明明注入了SessionFactory 为什么还是报这样的错误呀?'sessionFactory' or 'hibernateTemplate' is required
- ESB mule相关问题
- hibernate search 在spring中配置问题
- tomcat, webshpere的问题, 急 本人结贴信誉良好,有了答案马上给分
- 请问:如何把java.util.Date转化成java.sql.Date?
- unreported exception java.lang.InstantiationException; must be caught or declared to be thrown JAVA连接数据库难题
IE里面确实是可以访问这个URL:http://us01.xmlsearch.findwhat.com/bin/findwhat.dll的
connect到us01.xmlsearch.findwhat.com是可以的(Socket连接没有报异常)为什么程序里面取道的信息就不对呢?????
终于解决了这个问题,
开心,结贴