简体   繁体   English

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

[英]PHP Curl Error 35 Peer reports it experienced an internal error

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 Curl工作:我拥有使用api的域,并且可以对运行它的服务器进行任何更改。

<?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. Curl返回错误:Peer报告它遇到内部错误。 When I curl the domain itself ( https://www.somedomain.com ) it returns the same error. 当我卷曲域本身( https://www.somedomain.com )时,它将返回相同的错误。 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. 即使当我通过终端使用curl时,它也会返回35错误,但是当我尝试在不使用HTTPS的情况下对域进行卷曲时,它会返回找到的302,但是由于我的域仅为https,因此这不是解决方案,它只会显示移动页面。 I know this has something todo with curl using https but https://www.google.com works so I dont know where to start... 我知道这与使用https进行卷曲有关,但是https://www.google.com可以工作,所以我不知道从哪里开始...

Below is an answer in from php.net . 以下是来自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. 如果您收到错误代码为35的错误消息“与...有关的未知SSL协议错误”,则可能是您使用了错误密码。

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! 为我工作,可以为您工作! PS: Used with PHP 5.4 and cURL 7.26.0. PS:与PHP 5.4和cURL 7.26.0一起使用。

Unable to get Curl working I decided to use file_get_contents and stream_context_create. 无法使Curl工作,我决定使用file_get_contents和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: API /网络服务:

$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',
    '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));

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM