81,092
社区成员
发帖
与我相关
我的任务
分享
public static void main(String[] args) throws Exception {
System.setProperty( "org.apache.commons.logging.Log", "org.apache.commons.logging.impl.NoOpLog" ); //关闭日志
Protocol authhttps = new Protocol("https",
new AuthSSLProtocolSocketFactory( new URL("file:my.keystore"), "123456",
new URL("file:my.truststore"), "123456"),
443);
HttpClient client = new HttpClient();
client.getHttpConnectionManager().getParams().setConnectionTimeout(3000);
client.getHttpConnectionManager().getParams().setSoTimeout(3000);
client.getHostConfiguration().setHost("target.com", 443, authhttps);
/* 只能使用相对路径 */
GetMethod httpget = new GetMethod("/link");
client.executeMethod(httpget);
PostMethod httppost=new PostMethod("https://target.com");
httppost.setRequestHeader("Referer", "https://target.com");
httppost.setRequestHeader("Accept-Language", "en-US");
httppost.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
httppost.setRequestHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Mozilla/4.0)");
//httppost.setRequestHeader("Connection", "Keep-Alive");
//httppost.setRequestHeader("Cache-Control", "no-cache");
httppost.setParameter("id", id);
httppost.setParameter("link", link);
httppost.setParameter("tb", "e1s1");
httppost.setParameter("_eventId", "submit");
client.executeMethod(httppost);
String result = new String(httppost.getResponseBody());
httpget.releaseConnection(); //关闭连接
httppost.releaseConnection(); //关闭连接
}