日期:2014-05-20 浏览次数:20976 次
public static void main(String[] args) throws IOException { HttpClient client = new HttpClient(); // HttpMethod method = new GetMethod("http://www. baidu.com"); HttpMethod method = new GetMethod("http://www. baidu000.com"); int i=client.executeMethod(method); System.out.println(i); // 打印服务器返回的状态 System.out.println(method.getStatusLine());//HTTP/1.1 200 OK }
BufferedReader reader = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream())); String line = null; StringBuffer str = new StringBuffer(); line = reader.readLine(); if (null != line) { str.append(line); } while ((line = reader.readLine()) != null) { str.append(System.getProperty("line.separator")).append(line); } System.out.println("应答结果:" + str.toString());
------解决方案--------------------
有可能是被什么工具给跳转到其它地址了