php中没有数据结果curl

时间:2015-12-31 02:32:04

标签: php curl

我正在尝试使用PHP中的CURL发送一些表单字段,得到以下错误。但它不会返回结果。 我对addon邮递员进行了测试,然后返回结果 result using postman

function httpPost($url,$params = array())
{
    $postData = '';

    //create name value pairs seperated by &
    foreach($params as $k => $v)
    {
        $postData .= $k . '='.$v.'&';
    }
    $postData = rtrim($postData, '&');

    $ch = curl_init();

    curl_setopt($ch,CURLOPT_URL,$url);
    curl_setopt($ch, CURLOPT_REFERER, "https://www.sportsbetting.ag/sportsbook");
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
    curl_setopt($ch,CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
    print_r($postData);

    $output=curl_exec($ch);

    curl_close($ch);
    return $output;

}

$params = array(
        'param.PrdNo' => -1,
        'param.Type' => 'H2H',
        'param.RequestType' => 'Normal',
        'param.H2HParam.Lv1' => 'Basketball',
        'param.H2HParam.Lv2' => 'NBA'
);

echo httpPost("https://www.sportsbetting.ag/sportsbook/Line/RetrieveLineData",$params);here

1 个答案:

答案 0 :(得分:0)

您遇到此问题“SSL证书问题:无法获取本地颁发者证书”

修正了它:

    function httpPost($url,$params = array())
        {
            $postData = '';

            //create name value pairs seperated by &
            $postData = http_build_query($params); // Write less

            $ch = curl_init();

            curl_setopt($ch, CURLOPT_URL,$url);
            //curl_setopt($ch, CURLOPT_REFERER, "https://www.sportsbetting.ag/sportsbook");
            curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
            curl_setopt($ch, CURLOPT_HEADER, false);
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //Added to solve SSL problem

            $output=curl_exec($ch);
                $curl_errno = curl_errno($ch);
                //$curl_error = curl_error($ch);
                // Print it when you wanna debug the request
                //print($curl_error);

            curl_close($ch);
            return $output;

        }

        $params = array(
                'param.PrdNo' => -1,
                'param.Type' => 'H2H',
                'param.RequestType' => 'Normal',
                'param.H2HParam.Lv1' => 'Basketball',
                'param.H2HParam.Lv2' => 'NBA'
        );

$result = httpPost("https://www.sportsbetting.ag/sportsbook/Line/RetrieveLineData?",$params);
        //var_dump($result);
    return $result;