php - curl_setopt() 期望参数 1 为资源 - CURL 问题

标签 php curl

我的代码中有一个问题,我想通过 CURL(小支付网关)获取信息,但我有下一个问题...

警告:curl_setopt() 期望参数 1 为资源,在第 12 行的/home/xxxxxx/public_html/xxxxxxx/myaccount/xxxx.php 中给定为 null

我有接下来的代码行..

$getbin  = 'https://binlist.net/json/".$bin."';
    $get  = curl_init();
    curl_setopt($curl, CURLOPT_URL, $getbin);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
    $exec  = curl_exec($get);
    curl_close($get);
    $cc           = json_decode($exec);
    $ccbrand      = $cc->brand;
    $ccbank       = $cc->bank;
    $cctype       = $cc->card_type;
    $ccklas       = $cc->card_category;

你能帮帮我吗?非常感谢

最佳答案

您正在设置 curl_setopt options$curl,但初始化一个新 session (并返回一个 cURL 句柄)到 $get。您应该像这样更改 curl_setopt 行:

curl_setopt($get, CURLOPT_URL, $getbin);
curl_setopt($get, CURLOPT_RETURNTRANSFER, true);
curl_setopt($get, CURLOPT_FOLLOWLOCATION, true);

这样,您就可以为 cURL 句柄 $get 设置选项。

关于php - curl_setopt() 期望参数 1 为资源 - CURL 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39189221/

相关文章:

ruby-on-rails - 我如何在 curb 中指定 SSL 版本

php - JSON 和 CURL 问题

linux - 如何在 Linux 中查找 curl 本地(客户端)证书

php - 返回数组中最大值的索引

php - 这个 perl 正则表达式的 PHP 等价物是什么

php - 用于散列 8-16 字节字符串的非常快的散列函数

PHP MySQL 将帖子链接到用户

php - 如何获取给定用户和给定主题标签的所有推文?

c++ - 在 cURL C++ 中不保存 Cookie,这样一个简单干净的代码示例是行不通的

python - 在 REST API 的 HTTP/1.0 请求中省略 Accept */* header 是否是错误