利用httpclient模拟站点的登录发帖回复 - 编程入门网
作者 佚名技术
来源 NET编程
浏览
发布时间 2012-06-21
) { 44 client.getHostConfiguration().setProxy(proxyip.getIp(),proxyip.getPort()); 45 client.getParams().setAuthenticationPreemptive( true ); 46 // 泌惚旗尖俶勣畜鷹刮屬?宸戦譜崔喘薩兆畜鷹 47 // client.getState().setProxyCredentials(AuthScope.ANY, new UsernamePasswordCredentials("","")); 48 } 49 } 50 51 public HttpClient getClient() { 52 return client; 53 } 54 55 public Siteusers getUser() { 56 return user; 57 } 58 59 public void setUser(Siteusers user) { 60 this .user = user; 61 } 62 63 private BrowserContext(Site site) { 64 super (); 65 Protocol myhttps = new Protocol( " https " , new MySecureProtocolSocketFactory(), 443 ); 66 Protocol.registerProtocol( " https " , myhttps); 67 client = new HttpClient(); 68 client.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY); 69 HttpConnectionManagerParams managerParams = client.getHttpConnectionManager().getParams(); 70 // 譜崔銭俊階扮扮寂(汽了坐昼) 71 // managerParams.setConnectionTimeout(50000); 72 // 譜崔響方象階扮扮寂(汽了坐昼) 73 // managerParams.setSoTimeout(120000); 74 initForSiteVisit(site.getSite(),site.getPort(),site.getCharset()); 75 } 76 77 public BrowserContext(Site site,Proxyips proxyip) { 78 this (site); 79 this .setProxyip(proxyip); 80 } 81 82 private void initForSiteVisit(String siteurl, int port,String charset) { 83 client.getHostConfiguration().setHost(siteurl, port, " http " ); 84 // 盾畳嶄猟岱鷹諒籾?才峺協利嫋議匈中園鷹匯崑 85 client.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, charset); 86 } 87 88 // 臥心cookie佚連 89 public void printCookies() 90 { 91 System.out.println( " ---------------Cookie---------------- " ); 92 if (cookies != null ) { 93 for (Cookie c:cookies) { 94 System.out.println(c.getName() + " : " + c.getValue()); 95 } 96 } else { 97 System.out.println( " 短嗤譜崔Cookies " ); 98 } 99 System.out.println( " ---------------Cookie---------------- " ); 100 } 101 102 public void setCommonMethodRequestHeaders(HttpMethodBase method) 103 |
凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢! |
你可能对下面的文章感兴趣
关于利用httpclient模拟站点的登录发帖回复 - 编程入门网的所有评论