从curl_api()获取所有用户时,获取curl_error():2不是有效的cURL句柄资源 [英] Getting curl_error(): 2 is not a valid cURL handle resource while fetching all users from freshdesk api

查看:285
本文介绍了从curl_api()获取所有用户时,获取curl_error():2不是有效的cURL句柄资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建自己的系统,以管理来自freshdesk.com通过其API发出的所有票证.我正在发出卷曲请求以从freshdesk.com提取数据.通过获取与代码相关的数据,它可以正常工作,但是当我通过curl请求向所有用户请求时,它给我错误:

I am creating my own system to managing all tickets which are comes from freshdesk.com through its API. I am making curl request to fetch data from freshdesk.com. With getting data of related to tickers its works fine but when i am requesting for all users through curl request then its give me error:

警告::curl_errno():第28行的C:\ wamp \ www \ test.php中的2不是有效的cURL句柄资源.

Warning: curl_errno(): 2 is not a valid cURL handle resource in C:\wamp\www\test.php on line 28.

我的代码是这样的:

$ch = curl_init();  
$cOption = array(
    CURLOPT_URL            => 'http://velocity.freshdesk.com/contacts.xml',
    CURLOPT_HEADER         => 0,
    CURLOPT_USERPWD        => "$email:$password",
    CURLOPT_POST           => false,
    CURLOPT_HTTPHEADER     => array('Content-Type: application/xml'),
    CURLOPT_HTTPAUTH       => CURLAUTH_BASIC,
    CURLOPT_FAILONERROR    => 1,
    CURLOPT_SSL_VERIFYHOST => 2,
    CURLOPT_SSLVERSION     => 2
);  
@curl_setopt_array( $ch, $cOption );  
curl_close($ch);
echo curl_errno($ch);  //line 28
echo curl_error($ch);  //line 29
echo $ch_result;  

输出为:
警告::curl_errno():第28行的C:\ wamp \ www \ test.php中的2不是有效的cURL句柄资源.
警告::curl_errno():第29行的C:\ wamp \ www \ test.php中的2不是有效的cURL句柄资源.
1//回显$ ch_result的输出

Output is:
Warning: curl_errno(): 2 is not a valid cURL handle resource in C:\wamp\www\test.php on line 28.
Warning: curl_errno(): 2 is not a valid cURL handle resource in C:\wamp\www\test.php on line 29.
1 // output of echo $ch_result

请帮助我找出代码有什么问题以及为什么出现此警告.

Please help me to figure out what is wrong with the code and why this warnings occur.

推荐答案

关闭$ch后,请使用curl_errnocurl_error.不对.

You use curl_errno and curl_error after closing $ch. It is not right.

获取有关错误的信息后,您需要关闭$ch.

You need to close your $ch after fetching information about error.

echo curl_errno($ch);
echo curl_error($ch);
curl_close($ch);

您还没有为$ch_result设置任何内容.如果您期望它包含您的请求结果,那么您错了.要解决此问题,您需要添加选项CURLOPT_RETURNTRANSFER并使用$ch_result = curl_exec($ch);

Also you didn't set anything to $ch_result. If you expect that it contains result of your request you are wrong. To fix this you need to add option CURLOPT_RETURNTRANSFER and fetch the result with $ch_result = curl_exec($ch);

这篇关于从curl_api()获取所有用户时,获取curl_error():2不是有效的cURL句柄资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆