PHP curl请求返回false

时间:2018-01-12 10:19:09

标签: php curl

这是我的功能:

function postCurl($url, $jsql) {
    $data = array('sql' => $jsql);//jsql is a json string
    $headers = array('Content-Type: application/x-www-form-urlencoded');

    var_dump($data);
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,TRUE);
    $output = curl_exec($ch);

    return $output;
}

它始终返回false。我试图用REST客户端发出相同的请求,但它确实有效。

1 个答案:

答案 0 :(得分:0)

检查服务器是否启用了卷曲!!

并使用以下代码

$data = array('name' => $_REQUEST['name']);

            $ch = curl_init('www.example.com/');
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);  
            curl_setopt($ch, CURLOPT_POST, true);
            curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
            $response = curl_exec($ch);
            curl_close($ch);

            $xml_output = htmlentities($response);