当前位置: 代码迷 >> J2SE >> httpclient模拟登录百度https的有关问题
  详细解决方案

httpclient模拟登录百度https的有关问题

热度:2331   发布时间:2013-02-25 00:00:00.0
求助httpclient模拟登录百度https的问题
原来的用httpclient3.1的,现在用不了,谁能帮忙修改下,

或是帮忙提供httpclient4.0的模拟登录代码或是其他的代码? 

谢谢。

Java code
public  int publisharticle(User bu) {          HttpClient client=null;          HttpMethodParams params=new HttpMethodParams();         boolean pubSuccess=false;        try {            Protocol authhttps = new Protocol("https",                      new AuthSSLProtocolSocketFactory( new URL("file:///E:/https/my.keystore"), "1088111",                      new URL("file:///E:/https/my.truststore"), "aaaaa"),                      443);              client = new HttpClient();              //中文乱码            String CONTENT_CHARSET = "gb2312";                           client.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, CONTENT_CHARSET);              client.getHostConfiguration().setHost("passport.baidu.com", 443, authhttps);              /* 只能使用相对路径 */              GetMethod httpget = new GetMethod("/?login&tpl=mn");              client.executeMethod(httpget);             //System.out.println(new String(httpget.getResponseBody(),"gb2312"));              PostMethod httppost=new PostMethod("https://passport.baidu.com/?login");              httppost.setParameter("tpl_ok", "");              httppost.setParameter("next_target", "");              httppost.setParameter("tpl", "mn");              httppost.setParameter("skip_ok", "");              httppost.setParameter("aid", "");              httppost.setParameter("need_pay", "");              httppost.setParameter("need_coin", "");              httppost.setParameter("pay_method", "");              httppost.setParameter("u", "http://www.baidu.com/");              httppost.setParameter("return_method", "get");              httppost.setParameter("more_param", "");              httppost.setParameter("return_type", "");              httppost.setParameter("psp_tt", "0");              httppost.setParameter("password", bu.getPassword());              httppost.setParameter("safeflg", "0");              httppost.setParameter("isphone", "tpl");              httppost.setParameter("username", bu.getUsername());              httppost.setParameter("verifycode", "");              httppost.setParameter("mem_pass", "on");                           client.executeMethod(httppost);              StringBuffer sb=new StringBuffer();              Header[] heads=httppost.getResponseHeaders();              for (int i=0;i<heads.length;i++){                 // System.out.println(i+":"+heads[i].getName()+":"+heads[i].getValue());                  if(heads[i].getName().equalsIgnoreCase("Set-Cookie")){                      sb.append(heads[i].getValue()+";");                  }              }                           System.out.println("================"+new String(sb)+"======================");              int i=0;              InputStream ins=httppost.getResponseBodyAsStream();              while ((i=ins.read())!=-1){                 // System.out.print(i);              }              httppost.abort();        } catch (MalformedURLException e1) {            // TODO Auto-generated catch block            e1.printStackTrace();        } catch (HttpException e1) {            // TODO Auto-generated catch block            e1.printStackTrace();        } catch (UnsupportedEncodingException e1) {            // TODO Auto-generated catch block            e1.printStackTrace();        } catch (IOException e1) {            // TODO Auto-generated catch block            e1.printStackTrace();        }
  相关解决方案