如何绕过servlet中httpClient.executeMethod(httpPost)中的无效SSL证书错误

时间:2015-02-02 13:01:36

标签: java ssl httpclient

如何绕过无效的SSL证书错误?不需要安全连接!我看了相同的答案但没有结果。我尝试使用TrustManager,但在httpClient.getParams()。setContentCharset(CLIENT_CHARSET)中有错误。 继承人servlet示例代码:

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html; charset=windows-1251");
    java.io.PrintWriter out = response.getWriter();
    List listDoc=null;
    String dateDoc=new java.text.SimpleDateFormat("dd.MM.yyyy").format(java.util.Calendar.getInstance ().getTime());
    Date currentDate = new Date();
    Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT+03:00"));
    calendar.add(Calendar.DAY_OF_MONTH, -1);
    String yesterday=new java.text.SimpleDateFormat("dd.MM.yyyy").format(calendar.getTime());

    HttpClient httpClient = new HttpClient();
     httpClient.getParams().setContentCharset(CLIENT_CHARSET);
     if (request.getParameter("d")!=null)
     {
         yesterday=request.getParameter("d");
     }
     if (request.getParameter("k")!=null)
     {
         String id=request.getParameter("k");
         bean.setKontrNamesList(oracle.connect("Select * from NTR where konturl is not null and NTR.`LOAD`=1 and krid="+id+"","MS"));
            listDoc=oracle.connect("Select * from NTR where konturl is not null and NTR.`LOAD`=1 and krid="+id+"","MS");

     }
     else
     {
    bean.setKontrNamesList(oracle.connect("Select * from NTR where konturl is not null and NTR.`LOAD`=1","MS"));
    listDoc=oracle.connect("Select * from NTR where konturl is not null and NTR.`LOAD`=1","MS");
     } 

     bean.setTypeNamesList(oracle.connect("Select * from typedoc","KIR"));
    for (int i=0;i<listDoc.size();i++)
    {
        List ter1 = (List) listDoc.get(i);

        String req_string=ter1.get(1)+";"+ter1.get(2);
        System.out.println(ter1.get(1)+";"+ter1.get(2));
        PostMethod httpPost = new PostMethod(URI);
        httpPost.getParams().setContentCharset(CLIENT_CHARSET);
        String name=base.replace(ter1.get(0).toString(),"\"","");
        System.out.println(name+"  "+req_string);
        if (ter1.size()>3&&ter1.get(3)!=null&&ter1.get(3).toString().equals("1"))
        { 
         httpPost.addParameter(name,req_string);            
         httpPost.addParameter("dateDoc",yesterday);

         if (ter1.size()>7&&ter1.get(9)!=null&&ter1.get(9).toString().equals("1"))
             httpPost.addParameter("T12","T12");
         httpClient.executeMethod(httpPost);    
            }
    }       



}

更新 更新Java 1.6到Java 1.7解决了问题

0 个答案:

没有答案