81,091
社区成员
发帖
与我相关
我的任务
分享
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.cookie.CookiePolicy;
import org.apache.commons.httpclient.methods.GetMethod;
public class XCD {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
HttpClient client = new HttpClient();
List<Header> headers = new ArrayList<Header>();
headers.add(new Header("Host","17track.net"));
headers.add(new Header("User-Agent","Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; CIBA; .NET4.0C; .NET CLR 2.0.50727)"));
headers.add(new Header("Accept","image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/QVOD, application/QVOD, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/xaml+xml, application/x-ms-xbap, application/x-ms-application, */*"));
headers.add(new Header("Accept-Language","zh-cn"));
headers.add(new Header("Accept-Encoding","gzip, deflate,utf-8"));
headers.add(new Header("Accept-Charset","GB2312,utf-8;q=0.7,*;q=0.7"));
headers.add(new Header("Connection","Keep-Alive"));
client.getHostConfiguration().getParams().setParameter("http.default-headers", headers);
GetMethod method2 = new GetMethod("http://17track.net/Index.html");
method2.getParams().setCookiePolicy(CookiePolicy.DEFAULT);
try {
System.out.println(client.executeMethod(method2));
//System.out.println(method2.getResponseBodyAsString());
System.out.println(client.getState().getCookies().length);
} catch (HttpException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}