php curl 417 - 期望失败的帖子请求

时间:2017-02-03 08:53:46

标签: php windows curl debian virtual-machine

我想将$ data数组发布到 ip /crontab.php .. 有时它的工作就像巫术一样。但主要是ERROR 417失败了。

数组$ data在所有字段中设置。

VMWare Linux Debian 8.0可以访问!

这是我的代码:

public function output($data)
{

    printr($data);

    $url = 'http:// <ip-VMWare> /crontab.php';

    $curl = curl_init(); //Error 404
    curl_setopt($curl, CURLOPT_URL, $url); //return 1

    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); //Error  404
    curl_setopt($curl, CURLOPT_POST, 1); //Error  417

    curl_setopt($curl, CURLOPT_POSTFIELDS, $data); //Error  417
    curl_setopt($curl, CURLOPT_REFERER, $url); //Error  417

    curl_setopt($curl,CURLOPT_HTTPHEADER,array("Expect:  ")); //Error  404
    curl_setopt($curl, CURLOPT_HTTPHEADER, array("HeaderName: HeaderValue")); //Error  417

    $response = curl_exec($curl);
    print_r($response);


    if($response === FALSE)
    {
        echo 'cURL ERROR: '.$response;
    }

    curl_close($curl);

    exit; //stop the add process (only Testing the cURL)

    return 0;
}
<?php
//VMWare cronjob.php
echo 'ho';
if ($_POST['Serverip'] === '0')
{echo 'ho';
    echo 'ho';}
print_r($_POST);

?>

1 个答案:

答案 0 :(得分:2)

在lighttpd / 1.4.45服务器上,这对我有用:

curl_setopt( $curl, CURLOPT_HTTP_VERSION, '1.0' );

希望这会有所帮助