PHP Curl Error 35 Peer报告它遇到内部错误

I am trying to get PHP Curl working using the following code: I own the domain that is using the api and I can make any changes to the server that it is running on.

<?php
ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(-1);

$data = array("username" => "derped", "authid" => "987654321", "ipaddress" => "1.2.3.4", "apikey" => "1234567829");
$data_string = json_encode($data);
$url = 'https://www.somedomain.com/test/api.php';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: Content-Type: text/html'));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
if(curl_exec($ch) === false)
{
    echo curl_error($ch);
}
else
{
    echo 'ok';
}

curl_close($ch);

$received = json_decode($result);
$check = $received->{'good'};
echo $result;
echo $check;
?>

Curl returns the error: Peer reports it experienced an internal error. When I curl the domain itself (https://www.somedomain.com) it returns the same error. Even when I use curl via the terminal it returns the 35 error, but when I try to curl the domain without HTTPS it returns the 302 found but since my domain is https only this will not be the solution, it just echos the move page. I know this has something todo with curl using https but https://www.google.com works so I dont know where to start...

dtds8802
dtds8802 证书是官方证书(Comodo),我在我的SSL版本中提供了ca.将您的建议添加到代码后,它返回:无法与对等方安全地通信:没有通用的加密算法。将检查错误。
4 年多之前 回复
dsv73806
dsv73806 你的证书,是自签名的吗?您可能需要将verifypeer和/或verifyhost设置为0...
4 年多之前 回复

3个回答



以下是来自 php.net 。 显然它应该有助于解决未知协议问题... </ p>


如果您收到错误,错误代码35说“与...有关的未知SSL协议错误 “,也许你正在使用错误的密码。</ p>

尝试精确修改一堆密码,如下所示:</ p>
</ blockquote>

  $ arrayCiphers = array(
'DHE-RSA-AES256-SHA',
'DHE-DSS-AES256-SHA',
'AES256-SHA:KRB5-DES-CBC3-MD5',
'KRB5 -DES-CBC3-SHA',
'EDH-RSA-DES-CBC3-SHA',
'EDH-DSS-DES-CBC3-SHA',
'DES-CBC3-SHA:DES-CBC3-MD5 ',
'DHE-RSA-AES128-SHA',
'DHE-DSS-AES128-SHA',
'AES128-SHA:RC2-CBC-MD5',
'KRB5-RC4-MD5:KRB5 -RC4-SHA',
'RC4-SHA:RC4-MD5:RC4-MD5',
'KRB5-DES-CBC-MD5',
'KRB5-DES-CBC-SHA',
'EDH -RSA-DES-CBC-SHA',
'EDH-DSS-DES-CBC-SHA:DES-CBC-SHA',
'DES-CBC-MD5:EXP-KRB5-RC2-CBC-MD5',

'EX-KRB5-DES-CBC-MD5',
'EX-KRB5-RC2-CBC-SHA',
'EXP-KRB5-DES-CBC-SHA',
'EX-EDH-RSA -DES-CBC-SHA',
'EXP-EDH-DSS-D ES-CBC-SHA',
'EXP-DES-CBC-SHA',
'EXP-RC2-CBC-MD5',
'EXP-RC2-CBC-MD5',
'EX-KRB5- RC4-MD5',
'EX-KRB5-RC4-SHA',
'EXP-RC4-MD5:EXP-RC4-MD5');
curl_setopt($ ch,CURLOPT_SSL_CIPHER_LIST,implode(':',$ arrayCiphers ));
</ code> </ pre>


为我工作,可以为你工作!
PS:与PHP 5.4和cURL 7.26.0一起使用。</ p>
</ blockquote>
</ div>

展开原文

原文

Below is an answer in from php.net. Apparently it should help solve the unknown protocol issue...

If you get an error with the error code 35 saying "Unknown SSL protocol error in connection to ...", maybe you are using the wrongs ciphers.

Try to precise a bunch of ciphers as below:

$arrayCiphers = array(
    'DHE-RSA-AES256-SHA',
    'DHE-DSS-AES256-SHA',
    'AES256-SHA:KRB5-DES-CBC3-MD5',
    'KRB5-DES-CBC3-SHA',
    'EDH-RSA-DES-CBC3-SHA',
    'EDH-DSS-DES-CBC3-SHA',
    'DES-CBC3-SHA:DES-CBC3-MD5',
    'DHE-RSA-AES128-SHA',
    'DHE-DSS-AES128-SHA',
    'AES128-SHA:RC2-CBC-MD5',
    'KRB5-RC4-MD5:KRB5-RC4-SHA',
    'RC4-SHA:RC4-MD5:RC4-MD5',
    'KRB5-DES-CBC-MD5',
    'KRB5-DES-CBC-SHA',
    'EDH-RSA-DES-CBC-SHA',
    'EDH-DSS-DES-CBC-SHA:DES-CBC-SHA',
    'DES-CBC-MD5:EXP-KRB5-RC2-CBC-MD5',
    'EXP-KRB5-DES-CBC-MD5',
    'EXP-KRB5-RC2-CBC-SHA',
    'EXP-KRB5-DES-CBC-SHA',
    'EXP-EDH-RSA-DES-CBC-SHA',
    'EXP-EDH-DSS-DES-CBC-SHA',
    'EXP-DES-CBC-SHA',
    'EXP-RC2-CBC-MD5',
    'EXP-RC2-CBC-MD5',
    'EXP-KRB5-RC4-MD5',
    'EXP-KRB5-RC4-SHA',
    'EXP-RC4-MD5:EXP-RC4-MD5');
curl_setopt($ch, CURLOPT_SSL_CIPHER_LIST, implode(':', $arrayCiphers));

Worked for me, could work for you! P.S: Used with PHP 5.4 and cURL 7.26.0.

douang4294
douang4294 您想先尝试file_get_contents并对API进行简单测试吗? 该功能可以设置为POST。
4 年多之前 回复
douyiyang6317
douyiyang6317 Unfo它返回未知的密码列表; 我刚刚将curl升级到7.45,认为它会修复ssl问题,因为我的版本是7.29但是没有雪茄...仍然无法与对等方安全通信:没有常见的加密算法错误。 fsocket或fopen不是使用curl而是一个很好的选择,因为我只需要发布一块加密数据。 还检查了我的防火墙; 允许进出443
4 年多之前 回复
dongzaliang4492
dongzaliang4492 我将尝试匹配我在框中配置的密码,将回发结果。
4 年多之前 回复

Unable to get Curl working I decided to use file_get_contents and stream_context_create.

For those interested in an alternative:

Client:

$data = new stdClass();
$data->apikey = "1234567890";

$json_data = json_encode($data);

$post = file_get_contents('http://URL/api.php',null,stream_context_create(array(
    'http' => array(
        'method'           => 'POST',
        'content'          => $json_data,
    )
)));

if ($post) {
    echo $post;
} else {
    echo "POST failed";
}

API/Webservice:

$receive = fopen('php://input', 'r');
$received = stream_get_contents($receive);
$data = json_decode($received);
$apikey = $data->{'apikey'};
If($apikey == 1234567890)
{
    $response = array("good" => true);
    $goresponse = json_encode($response);
    print_r($goresponse);
}
else
{
    $response = array("good" => false);
    $goresponse = json_encode($response);
    print_r($goresponse);
}

Note that these are the basics, the stream would prob. need more arguments depending on the webservice restrictions, good luck!



  $ arrayCiphers = array(
'DHE-RSA-AES256-SHA',
'DHE-DSS-AES256 -SHA',
'AES256-SHA:KRB5-DES-CBC3-MD5',
'KRB5-DES-CBC3-SHA',
'EDH-RSA-DES-CBC3-SHA',
\ EDH -DSS-DES-CBC3-SHA',
'DES-CBC3-SHA:DES-CBC3-MD5',
'DHE-RSA-AES128-SHA',
'DHE-DSS-AES128-SHA',

'AES128-SHA:RC2-CBC-MD5',
'KRB5-RC4-MD5:KRB5-RC4-SHA',
'RC4-SHA:RC4-MD5:RC4-MD5',
'KRB5 -DES-CBC-MD5',
'KRB5-DES-CBC-SHA',
'EDH-RSA-DES-CBC-SHA',
'EDH-DSS-DES-CBC-SHA:DES-CBC -SHA',
'DES-CBC-MD5:EXP-KRB5-RC2-CBC-MD5',
'EXP-KRB5-DES-CBC-MD5',
'EX-KRB5-RC2-CBC-SHA ',
'EX-KRB5-DES-CBC-SHA',
'EX-EDH-RSA-DES-CBC-SHA',
'EXP-EDH-DSS-DES-CBC-SHA',
'EXP-DES-CBC-SHA',
'EXP-RC2-CBC-MD5',
'EXP-RC2-CBC-MD5',
'EXP-KRB5-RC4-MD5',
'EX -KRB5-RC4-SHA',
'EXP-RC4-MD5:EXP-RC4-MD5');

ncurl_setopt($ ch,CURLOPT_SSL_CIPHER_LIST,implode(':',$ arrayCiphers));
</ 代码> </ pre>
</ d 四>

展开原文

原文

$arrayCiphers = array(
    'DHE-RSA-AES256-SHA',
    'DHE-DSS-AES256-SHA',
    'AES256-SHA:KRB5-DES-CBC3-MD5',
    'KRB5-DES-CBC3-SHA',
    'EDH-RSA-DES-CBC3-SHA',
    'EDH-DSS-DES-CBC3-SHA',
    'DES-CBC3-SHA:DES-CBC3-MD5',
    'DHE-RSA-AES128-SHA',
    'DHE-DSS-AES128-SHA',
    'AES128-SHA:RC2-CBC-MD5',
    'KRB5-RC4-MD5:KRB5-RC4-SHA',
    'RC4-SHA:RC4-MD5:RC4-MD5',
    'KRB5-DES-CBC-MD5',
    'KRB5-DES-CBC-SHA',
    'EDH-RSA-DES-CBC-SHA',
    'EDH-DSS-DES-CBC-SHA:DES-CBC-SHA',
    'DES-CBC-MD5:EXP-KRB5-RC2-CBC-MD5',
    'EXP-KRB5-DES-CBC-MD5',
    'EXP-KRB5-RC2-CBC-SHA',
    'EXP-KRB5-DES-CBC-SHA',
    'EXP-EDH-RSA-DES-CBC-SHA',
    'EXP-EDH-DSS-DES-CBC-SHA',
    'EXP-DES-CBC-SHA',
    'EXP-RC2-CBC-MD5',
    'EXP-RC2-CBC-MD5',
    'EXP-KRB5-RC4-MD5',
    'EXP-KRB5-RC4-SHA',
    'EXP-RC4-MD5:EXP-RC4-MD5');

curl_setopt($ch, CURLOPT_SSL_CIPHER_LIST, implode(':', $arrayCiphers));

douweng1935
douweng1935 解释一下你的解决方案。
2 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问