在不禁用SSL的情况下代码不起作用 [英] Code does not work without disabling SSL

查看:95
本文介绍了在不禁用SSL的情况下代码不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请查看此代码:

<?php
$url = "the_source_url";  
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$result = curl_exec($ch);
print_r($result);
?>

这个网页是由我的Android应用程式存取,以从某个来源取得日期。 url 返回一个json数据,我打印回来,然后,在我的应用程序中,我处理数据并显示它。

This page is accessed by my Android app to get a date from some source. The url returns a json data, which I print back, then, in my app, I process the data and display it. This is working fine for me right now (I'm still in the testing phase).

我读了,禁用 SSL

I read in SO that disabling the SSL (whih I did in line 6) is risky and not recommended. However, I couldn't make my script work unless I disable it.

如何使它的工作,而不禁用SSL?或者如何消除风险?

How to make it work without disabling the SSL? Or how to eliminate the risk?

推荐答案

禁用证书会使你容易受到中间人攻击,证书

Disabling the certificate would make you vulnerable to man in the middle attack, You can download use the certificate

curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt ($ch, CURLOPT_CAINFO, "PATH_TO_CERTIFICATE/cert.pem");

获取证书遵循本指南

然后点击查看证书:

打开cerficates页面的详细信息选项卡,然后选择层次结构顶部的证书。这是CA证书。

Bring up the "Details" tab of the cerficates page, and select the certificate at the top of the hierarchy. This is the CA certificate.

然后单击导出,将CA证书保存到所选位置,确保选择X.509证书(PEM)作为保存类型/格式。

Then click "Export", and save the CA certificate to your selected location, making sure to select the X.509 Certificate (PEM) as the save type/format.

>

图片来源:http://unitstep.net/

这篇关于在不禁用SSL的情况下代码不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆