0
因此,我使用此代碼登錄到發佈的網站... 及其無法使用。實際上,它不返回狀態,只是一個200和登錄站點。 ???使用HttpClient進行網站登錄
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.params.HttpMethodParams;
public class GetCookiePrintAndSetValue {
public GetCookiePrintAndSetValue() {
super();
}
public static void main(String[] args) throws Exception {
HttpClient client = new HttpClient();
client.getParams().setParameter(
HttpMethodParams.USER_AGENT,
"Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.2) Gecko/20100316 Firefox/3.6.2"
);
client.getState().setCredentials(
new AuthScope("https://gs.bcp.pinnacle,org", 443, "ANY_REALM"),
new UsernamePasswordCredentials("214416", "PassWord")
);
PostMethod get = new PostMethod("https://gs.bcp.org/Pinnacle/piv/logon.aspx");
get.setDoAuthentication(true);
try {
int status = client.executeMethod(get);
System.out.println(status + "\n" + get.getResponseBodyAsString());
} finally {
get.releaseConnection();
}
}
}
但是200是狀態:[Http狀態代碼](http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html)。 200 beeing OK – TPete 2012-02-10 08:10:17