doupai5450 2015-08-11 10:05
浏览 57
已采纳

尝试获取http post响应php时curl_setopt()错误

I have a code like this

    $payUrl = (some url);
    $postCheckData = 'CompanyCode=' . urlencode($companyCode) . '&ServiceCode=' . urlencode($serviceCode) and so on

    $chOne = curl_init( $payUrl );
    curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt( $ch, CURLOPT_POST, 1);
    curl_setopt( $ch, CURLOPT_POSTFIELDS, $postCheckData);
    curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt( $ch, CURLOPT_HEADER, 0);
    curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);
    $payResp = curl_exec( $chOne );
    curl_close ($chOne);
    print_r($payResp);

When I try to run this code, I get curl_setopt(): 248 is not a valid cURL handle resource What is this error? None of the solutions that I have searched worked for me.. What can be the possible problem? Please help

  • 写回答

1条回答 默认 最新

  • dsf11t5u1651 2015-08-11 10:09
    关注

    you initialise the curl request using $chOne = curl_init( $payUrl ); but then refer to $ch for all the other curl_setopt calls. I think it should look like this:

    $payUrl = (some url);
    $postCheckData = 'CompanyCode=' . urlencode($companyCode) . '&ServiceCode=' . urlencode($serviceCode) and so on
    
    $chOne = curl_init( $payUrl );
    curl_setopt( $chOne, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt( $chOne, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt( $chOne, CURLOPT_POST, 1);
    curl_setopt( $chOne, CURLOPT_POSTFIELDS, $postCheckData);
    curl_setopt( $chOne, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt( $chOne, CURLOPT_HEADER, 0);
    curl_setopt( $chOne, CURLOPT_RETURNTRANSFER, 1);
    $payResp = curl_exec( $chOne );
    curl_close( $chOne );
    
    print_r( $payResp );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?