最近发布了一个关于HttpClient过度Https 的问题(在这里找到).我已经取得了一些进展,但我遇到了新的问题.和我的上一个问题一样,我似乎无法找到适合我的任何地方的例子.基本上,我希望我的客户端接受任何证书(因为我只指向一个服务器),但我一直在接受javax.net.ssl.SSLException: Not trusted server certificate exception.
所以这就是我所拥有的:
public void connect() throws A_WHOLE_BUNCH_OF_EXCEPTIONS {
HttpPost post = new HttpPost(new URI(PROD_URL));
post.setEntity(new StringEntity(BODY));
KeyStore trusted = KeyStore.getInstance("BKS");
trusted.load(null, "".toCharArray());
SSLSocketFactory sslf = new SSLSocketFactory(trusted);
sslf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(new Scheme ("https", sslf, 443));
SingleClientConnManager cm = new SingleClientConnManager(post.getParams(),
schemeRegistry);
HttpClient client = new DefaultHttpClient(cm, post.getParams());
HttpResponse result = client.execute(post);
}
Run Code Online (Sandbox Code Playgroud)
这是我得到的错误:
W/System.err( 901): javax.net.ssl.SSLException: Not trusted server certificate
W/System.err( 901): at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:360)
W/System.err( 901): …Run Code Online (Sandbox Code Playgroud) 我做了一些关于这个主题的研究,有些专家说过这是不可能的,所以我想问一个替代解决方案.
我的情况:
页面A:[checkout.php]客户填写其结算明细.
页面B:[process.php]生成发票编号并将客户详细信息存储在数据库中.
页面C:[thirdparty.com]第三个支付网关(仅接受发布数据).
客户填写他们的详细信息并在页面A中设置他们的购物车,然后POST到页面B.在process.php内部,将POSTed数据存储在数据库中并生成发票编号.之后,将客户数据和发票号码发布到thirdparty.com支付网关.问题是在页面B中进行POST .cURL能够将数据发布到页面C,但问题是页面没有重定向到页面C.客户需要在页面C上填写信用卡详细信息.
第三方支付网关确实给了我们API样本,样本是POST发票号和客户详细信息.我们不希望系统生成多余的不需要的发票号.
这有什么解决方案吗?我们当前的解决方案是让客户填写页面A中的详细信息,然后在页面B中创建另一个页面,显示其中的所有客户详细信息,用户可以单击确认按钮POST到页面C.
我们的目标是让客户只需点击一次.
希望我的问题很明确:)
我正在尝试连接到运行godaddy 256位SSL证书的IIS6盒子,我收到错误:
java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
Run Code Online (Sandbox Code Playgroud)
一直试图确定可能导致这种情况的原因,但现在正在绘制空白.
这是我如何连接:
HttpsURLConnection conn;
conn = (HttpsURLConnection) (new URL(mURL)).openConnection();
conn.setConnectTimeout(20000);
conn.setDoInput(true);
conn.setDoOutput(true);
conn.connect();
String tempString = toString(conn.getInputStream());
Run Code Online (Sandbox Code Playgroud) 如何使用Apache HttpClient 4.0 绕过无效的SSL证书错误?
我正在做一个https帖子,我得到ssl异常的例外不可信服务器证书.如果我做正常的http它工作得很好.我必须以某种方式接受服务器证书吗?
我一直在使用以下代码连接到谷歌的服务之一.这段代码在我的本地机器上工作正常:
HttpClient client=new DefaultHttpClient();
HttpPost post = new HttpPost("https://www.google.com/accounts/ClientLogin");
post.setEntity(new UrlEncodedFormEntity(myData));
HttpResponse response = client.execute(post);
Run Code Online (Sandbox Code Playgroud)
我将此代码放在生产环境中,该环境已阻止Google.com.根据要求,他们允许我访问IP:74.125.236.52(这是Google的IP之一),允许与Google服务器进行通信.我编辑了我的hosts文件也添加了这个条目.
我仍然无法访问URL,我想知道为什么.所以我用上面的代码替换了:
HttpPost post = new HttpPost("https://74.125.236.52/accounts/ClientLogin");
Run Code Online (Sandbox Code Playgroud)
现在我收到这样的错误:
javax.net.ssl.SSLException:证书中的主机名不匹配:<74.125.236.52>!= <www.google.com>
我想这是因为Google有多个IP.我不能让网络管理员允许我访问所有这些IP - 我甚至可能没有得到这整个列表.
我现在应该怎么做 ?Java级别有解决方法吗?或者它完全掌握在网络人手中?
获取"javax.net.ssl.SSLPeerUnverifiedException: No peer certificate error"运行Android 2.3但不是4的模拟器.在4中它完美运行.我正在尝试通过https连接到实时服务器.它使用有效的Thawte证书,适用于所有浏览器和Android 3和4.
如果有人有代码帮助,请,谢谢.此外,如果有人对安全的解决方法有任何建议,我会很感激.我还在学习,我已经解决了这个问题一个星期了.它必须结束,所以我可以继续工作和学习.Urgh.
这是HttpCLient代码,礼貌Antoine Hauck(http://blog.antoine.li/2010/10/22/android-trusting-ssl-certificates/):
import java.io.InputStream;
import java.security.KeyStore;
import java.security.cert.CertificateException;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import javax.security.cert.X509Certificate;
import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.conn.scheme.PlainSocketFactory;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.conn.SingleClientConnManager;
import android.content.Context;
public class MyHttpClient extends DefaultHttpClient {
final Context context;
public MyHttpClient(Context context) {
this.context = context;
}
@Override
protected ClientConnectionManager createClientConnectionManager() {
SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
// Register for port 443 …Run Code Online (Sandbox Code Playgroud) 我在Android上使用HttpClient连接到https://someUrl.com/somePath.问题是网站的证书是针对*.someUrl.com而不是someUrl.com的,所以我得到了一个SSLException.网站上有跛脚,是的,但除非我能解决这个问题,否则我会陷入困境.有没有办法让HttpClient放松并接受证书?
我有一个移动应用程序(iPhone和Android),允许用户登录他的帐户,更改首选项等...
我想添加一个新功能,用户可以通过他的设备购买产品或升级他的服务.一切都将从设备运行,我想让用户使每个事务同步到Web服务器.
我的服务器上有HTTPS设置.我想知道是否:
谢谢
我开发了一个明确有效的HTTP GET方法.
public class GetMethodEx {
public String getInternetData() throws Exception{
new TrustAllManager();
new TrustAllSSLSocketFactory();
BufferedReader in = null;
String data = null;
try
{
HttpClient client = new DefaultHttpClient();
URI website = new URI("https://server.com:8443/Timesheets/ping");
HttpGet request = new HttpGet();
request.setURI(website);
HttpResponse response = client.execute(request);
response.getStatusLine().getStatusCode();
in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
StringBuffer sb = new StringBuffer("");
String l = "";
String nl = System.getProperty("line.separator");
while ((l = in.readLine()) !=null){
sb.append(l + nl);
}
in.close();
data = sb.toString();
return data;
} …Run Code Online (Sandbox Code Playgroud) ssl ×7
android ×5
java ×5
https ×3
certificate ×1
get ×1
http ×1
httpclient ×1
lamp ×1
php ×1
post ×1
security ×1
transactions ×1