In the school Park network, to agents to the Internet. What to do when writing a program to get online resources. You can also set up a proxy for your program. I use the 3.1 version of HttpClient. Some websites can be accessed by the browser, but the program can be browser-like, mainly set HTTP headers.
Set in Hostconfiguration.setproxy. such as the following code: package com.chenlb; import java.io.ioexception; import java.util.arraylist; import java.util.list; import org.apache.commons.httpclient.defaulthttpmethodretryhandler; import org.apache.commons.httpclient.header; import org.apache.commons.httpclient.httpclient; import org.apache.commons.httpclient.httpexception; import org.apache.commons.httpclient.httpstatus; 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.params.httpmethodparams; public class httpclientuse {     PUBLIC&NBSp;static void main (String[] args) throws httpexception, ioexception { HttpClient httpClient = new HttpClient (); Httpclient.gethostconfiguration (). SetProxy ("localhost", 808); /*//Need verification Usernamepasswordcredentials creds = new usernamepasswordcredentials ("Chenlb", "123456 "); httpclient.getstate (). Setproxycredentials ( authscope.any, creds); */ //Set HTTP headers list
If you want the username and password to be verified, please remove the/* */comment. Make validation valid.
Verification, the key is: usernamepasswordcredentials creds = new Usernamepasswordcredentials ("Chenlb", "123456"); Httpclient.getstate (). Setproxycredentials (Authscope.any, creds);
Sets the HTTP request header. list