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

报告相同问题?

悬赏问题

  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。
  • ¥20 CST怎么把天线放在座椅环境中并仿真