又是重定向问题比如输入 www.yahoo.com.cn 怎么知道 cn.yahoo.com 打开www.yahoo.com.cn 怎么会 con.getResponseCode() 不等于 HttpURLConnection.HTTP_OK 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我的代码是:import java.io.*;import java.net.*;public class webgethead { /** * @param args */ public static void main(String s[]) { System.out.println(exists("http://www.sina.com.cn")); System.out.println(exists("http://localhost/1.asp")); System.out.println(exists("http://www.yahoo.com.cn")); } static boolean exists(String URLName){ try { HttpURLConnection.setFollowRedirects(false); HttpURLConnection con = (HttpURLConnection) new URL(URLName).openConnection(); //con.setRequestMethod ("HEAD"); //con.setFollowRedirects(true); //即使加上也没有用 if (con.getResponseCode() == HttpURLConnection.HTTP_OK){ System.out.println(); System.out.print( "getHeaderFields:" + con.getHeaderField("X-Cache")); System.out.println(); return true; }else{ return false; } } catch (Exception e) { e.printStackTrace(); return false; } }} 通配符泛型数组 不理解 jFileChooser&&jProgressBar IBM面试题(考察编程基本功) 对象问题! 关于一个网络通讯的问题! 一个很头疼的问题佷(继) 请问用JAVA做QQ这样的程序要用到什么技术?在线等(急) 有没有Java读写CAD文件(.dwg或.dxf)的开源库呢? 不用swing,如何手工代码生成工具条和菜单条? java的线程问题。难! java socket和winsocket 之间的乱码问题 求救:哪位有树结点显示成checkbox的javascript代吗!!
import java.net.*;
public class webgethead { /**
* @param args
*/
public static void main(String s[]) {
System.out.println(exists("http://www.sina.com.cn"));
System.out.println(exists("http://localhost/1.asp"));
System.out.println(exists("http://www.yahoo.com.cn"));
} static boolean exists(String URLName){
try {
HttpURLConnection.setFollowRedirects(false);
HttpURLConnection con =
(HttpURLConnection) new URL(URLName).openConnection();
//con.setRequestMethod ("HEAD");
//con.setFollowRedirects(true); //即使加上也没有用
if (con.getResponseCode() == HttpURLConnection.HTTP_OK){
System.out.println();
System.out.print( "getHeaderFields:" + con.getHeaderField("X-Cache"));
System.out.println();
return true;
}else{
return false;
}
}
catch (Exception e) {
e.printStackTrace();
return false;
}
}}