Java读取Web页面信息
/*
 *
 * @parm httpConn an object of class HttpURLConnection
 * @param url an object of URL
 */
httpConn = (HttpURLConnection)url.openConnection();
httpConn.connect();
InputStream cin = httpConn.getInputStream();

 可以实现Java读取一个Web页面的信息,如果用Java读取一个需要登录认证的Web页面的信息,应该怎么实现或者在此基础上做些什么改进???

9个回答

httpclient 模拟登陆网站 获取网站内容程序
package org.apache.http.examples.client;

import java.io.IOException;

import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.cookie.*;
import org.apache.commons.httpclient.methods.*;

public class FormLoginDemo {
static final String LOGON_SITE = "www.intellitrans.com.cn";
static final int LOGON_PORT = 8081;
static final String loginurl = "/zyzg/logon.do";
static final String loginparematername = "userName";
static final String loginparematerpass = "password";
static final String username = "wangpx";
static final String password = "111111";

static final String getUrl = "/zyzg/hrmsub/hrm-deptlist.do"; 


public static void main(String[] args) throws Exception { 
    HttpClient client = imitateLogin(LOGON_SITE, LOGON_PORT, loginurl, loginparematername, loginparematerpass, username, password); 
    // 访问所需的页面 
    imitateGetUrl(client, getUrl); 
} 

//模拟等录 
private static HttpClient imitateLogin(String LOGON_SITE, int LOGON_PORT, 
        String loginurl,String loginparematername,String loginparematerpass,String username,String password) throws IOException, HttpException { 
    HttpClient client = new HttpClient(); 
    client.getHostConfiguration().setHost(LOGON_SITE, LOGON_PORT); 
    // 模拟登录页面 
    PostMethod post = new PostMethod(loginurl); 
    NameValuePair name = new NameValuePair(loginparematername,username ); 
    NameValuePair pass = new NameValuePair(loginparematerpass,password ); 
    post.setRequestBody(new NameValuePair[] { name, pass }); 
    int status = client.executeMethod(post); 
    System.out.println(post.getResponseBodyAsString()); 
    post.releaseConnection(); 
    // 查看cookie信息 
    CookieSpec cookiespec = CookiePolicy.getDefaultSpec(); 
    Cookie[] cookies = cookiespec.match(LOGON_SITE, LOGON_PORT, "/", false, 
            client.getState().getCookies()); 
    if (cookies != null) 
        if (cookies.length == 0) { 
            System.out.println("None"); 
        } else { 
            for (int i = 0; i < cookies.length; i++) { 
                System.out.println(cookies[i].toString()); 
            } 
        } 
    return client; 
} 
//模拟等录 后获取所需要的页面 
private static void imitateGetUrl(HttpClient client, String getUrl) 
        throws IOException, HttpException { 
    PostMethod post2 = new PostMethod(getUrl); 
    // GetMethod get = new 
    // GetMethod("/social/article/gallery_show/p_104846/"); 
    client.executeMethod(post2); 
    System.out.println(post2.getResponseBodyAsString()); 
    post2.releaseConnection(); 
} 

}

[url]http://www.iteye.com/topic/239910[/url]

[code="java"]String post = "email=" + URLEncoder.encode("e-mail", "UTF-8")

+ "&password=" + "password";

url = new URL(urlStr);

httpConn = (HttpURLConnection) url.openConnection();

//setInstanceFollowRedirects can then be used to set if

//redirects should be followed or not and this should be used before the

//connection is established (via getInputStream, getResponseCode, and other

//methods that result in the connection being established).

httpConn.setFollowRedirects(false);

//inorder to disable the redirects

httpConn.setInstanceFollowRedirects(false);

httpConn.setDoOutput(true);

httpConn.setDoInput(true);

httpConn.setRequestProperty("User-Agent",

"Mozilla/5.0 (compatible; MSIE 6.0; Windows NT)");

httpConn.setRequestProperty("Content-Type",

"application/x-www-form-urlencoded");

//ok now, we can post it

PrintStream send = new PrintStream(httpConn.getOutputStream());

send.print(post);

send.close();

URL newURL = new URL(httpConn.getHeaderField("Location"));

System.out.println("the URL has move to "

+ httpConn.getHeaderField("Location"));

httpConn.disconnect(); [/code]

看看这个全面的资料:

http://benlsoft.iteye.com/blog/97059

如果觉得上面代码写的不规范(因为注释太少了!看没注释的代码简直是要人命哦)

看看下面带注释齐全的代码吧。

[url=http://hi.baidu.com/relayon/blog/item/b03aee584e09aa8a810a181e.html]http://hi.baidu.com/relayon/blog/item/b03aee584e09aa8a810a181e.html[/url]

http post的提交呀
可以使用HttpClient API,挺不错。

恩,很简单。花时间最多是在看网页,你知道把form表单里面的提交元素都加上,一般就可以获取到form表单返回的结果页面。

[code="java"]

public String post(String url,NameValuePair[] param){

String content = null;

PostMethod postMethod = null;

StringBuilder origin = null;

try{

org.apache.commons.httpclient.HttpClient httpClient = new org.apache.commons.httpclient.HttpClient();

httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(5000*2);

postMethod = new UTF8PostMethod(url);

//设置 get 请求超时为 5 秒

postMethod.getParams().setParameter(HttpMethodParams.SO_TIMEOUT,5000);

//设置请求重试处理,用的是默认的重试处理:请求三次

postMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,

new DefaultHttpMethodRetryHandler());

origin = new StringBuilder();

origin.setLength(0);

NameValuePair e = new NameValuePair("question", "");

NameValuePair f = new NameValuePair("txtemail","");

NameValuePair a = new NameValuePair("__EVENTARGUMENT", "Page$2");

NameValuePair b = new NameValuePair("__EVENTTARGET", "GridView1");

NameValuePair c = new NameValuePair("__EVENTVALIDATION", "/wEWDgK9vY/sDwKtsp64BAKtsuK4BAKtsva4BAKtsvq4BAKtsu64BAKtsvK4BAKtssa4BAKtssq4BALDuK6IBQKokYx1AoTz/f8JAovVtt4BAtLCmdMIxqelNVHedagNCCFjz+7sRzFHnL8=");

NameValuePair d = new NameValuePair("__VIEWSTATE","/wEPDwUKMTQ3MDg4ODIwOA9kFgICAw9kFhgCAQ8WAh4LXyFJdGVtQ291bnQCARYCZg9kFgJmDxUKTUluYXVndXJhdGlvbiBvZiA5IHBsYW5zIG9mIHdhdGVyIGFuZCBzb2lsIGluIHRoZSBwcm92aW5jZSBTaXN0YW4tQmFsb29jaGVzdGFuPE92ZXIgMzkgdG9ucyBvZiBIb25leSB3YXMgcHJvZHVjZWQgYnkgYmVlIGdyb3dlcnMgb2YgS2FzaG1hckgyMSBwZXJjZW50IG9mIGluY3JlYXNlIGluIHRoZSBwdXJjaGFzZSBvZiBzdWdhciBiZWV0IGluIHRoZSBjdXJyZW50IHllYXJVVGhlIGFjdCBvZiBJcmFu4oCZcyBtZW1iZXJzaGlwIGluIHRoZSBpbnRlcm5hdGlvbmFsIHNvY2lldHkgb2YgZ2FyZGVuaW5nIHdhcyBhcHByb3ZlZE0xNSB0aG91c2FuZCBiaWx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WtpZGQCAw8PFgIfAgUHIElpbm8sIGRkAgUPDxYCHwIFI1NlY29uZCBTZWNyZXRhcnkgb2YgSmFwYW4ncyBFY29ub215ZGQCBw8PFgQfBAUSZGlhbG9ndWUuYXNweD9pZD02HwIFMkphcGFuIGltcG9ydHMgNjAgcGVyY2VudCBvZiBpdHMgYWdyaWN1bHR1cmFsIG5lZWRzZGQCAw8PFgIfBmhkZAIEDw8WAh8GaGRkAikPD2QPEBYBZhYBFgIeDlBhcmFtZXRlclZhbHVlZBYBAgNkZAIrDw9kDxAWAWYWARYCHwdkFgECA2RkGAMFHl9fQ29udHJvbHNSZXF1aXJlUG9zdEJhY2tLZXlfXxYBBQxJbWFnZUJ1dHRvbjEFCmRpYWxvZ3VlZ3YPPCsACgEIAgFkBQlHcmlkVmlldzEPPCsACgEIAscBZBrLrf2e8wAs7AhMzNbXamRx3Zlh");

// NameValuePair a = new NameValuePair("page","2");

// NameValuePair b = new NameValuePair("column_id","440");

// NameValuePair c = new NameValuePair("scolumn_id","1");

NameValuePair[] params = new NameValuePair[]{a,b,c,d,e,f};

postMethod.setRequestBody(params);

//postMethod.setRequestBody(param);

//执行getMethod

int statusCode = httpClient.executeMethod(postMethod);

if (statusCode != HttpStatus.SC_OK) {

System.err.println("Method failed: "+ postMethod.getStatusLine());

}else{

//读内容

String response = postMethod.getResponseBodyAsString();

content = response;

}

}catch(Exception e){

e.printStackTrace();

}finally{

postMethod = null;

origin = null;

}

return content;

}

[/code]

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!