简体   繁体   English

如何将安全性Cookie传递到HttpClient Get请求(Apache Commons)

[英]How to pass security cookies into a HttpClient Get request (Apache Commons)

I need to invoke a GET request on a URL which requires authentication. 我需要在需要身份验证的URL上调用GET请求。 I am able to get around this when doing a curl by simply passing in values for the remember me and jSession cookies like so... 我可以通过简单地传递“记住我”和jSession cookie的值来解决此问题,就像这样...

curl -v -b "mysite_remember_me=MToxNDU5MzcwODg1MDU1Ojk0YmYwMjI1NDI5MTZZkMGM2NzRkMzkx;JSESSIONID=2FDB2480CD28D99147C281.app1" "www.mysite.com/doSomething/play/416?confirmed=false&contentType=2"

But when I try to replicate this in Java like so... 但是当我尝试像这样在Java中复制它时...

HttpMethod method = new GetMethod("www.mysite.com/doSomething/play/416?confirmed=false&contentType=2&source=sourceSku")

org.apache.commons.httpclient.Cookie cookie1 = new
    org.apache.commons.httpclient.Cookie();

org.apache.commons.httpclient.Cookie cookie2 = new
    org.apache.commons.httpclient.Cookie();

cookie1.setName("mysite_remember_me");
cookie1.setValue("MToxNDU5MzcwODg1MDU1Ojk0YmYwMjI1NDI5MTZZkMGM2NzRkMzkx");

 cookie2.setName("JSESSIONID");
 cookie2.setValue("2FDB2480CD28D99147C281.app1");

httpClient.getState().addCookie(cookie1);
httpClient.getState().addCookie(cookie2);

responseCode = httpClient.executeMethod(method)

I get this exception... 我得到这个例外...

Caught: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed:  sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
  javax.net.ssl.SSLHandshakeException:   sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:174)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1747)

The problem I believe is that the SSL certificate on the target server hasn't been installed into your JRE's cacerts file. 我认为问题是目标服务器上的SSL证书尚未安装到JRE的cacerts文件中。 The error is due to your Java application not trusting the target url's SSL cert when invoking the URL with HTTP Client. 该错误是由于您的Java应用程序在使用HTTP客户端调用URL时不信任目标URL的SSL证书。 First get that installed using a java tool like http://opentox.ntua.gr/files/InstallCert.zip . 首先使用诸如http://opentox.ntua.gr/files/InstallCert.zip之类的Java工具进行安装。

See http://www.opentox.org/tutorials/q-edit/how-to-install-ssl-certificates on how to do this. 有关如何执行此操作的信息,请参见http://www.opentox.org/tutorials/q-edit/how-to-install-ssl-certificates

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 org.apache.commons.httpclient.HttpClient卡在请求上 - org.apache.commons.httpclient.HttpClient stuck on request 如何为Apache Commons httpclient注册URL处理程序 - how to register url handler for apache commons httpclient 使用Apache commons HttpClient时,如何覆盖请求中的“Host”标头 - How can I override the “Host” header in the request when using Apache commons HttpClient 如何在使用基于表单的Spring安全性对Java应用程序进行身份验证后使用Apache HttpClient来持久化cookie - How to persist cookies using Apache HttpClient after authenticating against Java app with form-based spring security 如何使用 HttpClient 获取 Cookie - How to get Cookies using HttpClient 如何使用Apache HttpClient 4.3处理Cookie - How to handle Cookies with Apache HttpClient 4.3 apache commons httpclient 4.23表单登录问题在不同请求中使用了不同的会话cookie - apache commons httpclient 4.23 form login problems different session cookies used in different requests 用于HTTPS调用的Apache Commons HttpClient - Apache Commons HttpClient for HTTPS call Apache Commons HttpClient PostMethod 支持? - Apache Commons HttpClient PostMethod support? 为什么我从Jakarta Commons HttpClient收到空请求? - Why do I get empty request from the Jakarta Commons HttpClient?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM