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 );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!