PHP 卷曲 CURLOPT_IPRESOLVE [英] PHP Curl CURLOPT_IPRESOLVE

查看:30
本文介绍了PHP 卷曲 CURLOPT_IPRESOLVE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在开发一个使用 facebook 图形 API 进行身份验证的 facebook 应用程序,最近 facebook 升级到 IPv6 并且我的网络不支持 IPv6 所以我所有的调用开始返回主机是无法访问的错误,我搜索了 facebook 错误和发现我们仍然可以使用 CURL CURLOPT_IPRESOLVE 强制要求 Facebook 使用 IPv4.

I have been working on a facebook application which uses facebook graph API for authentication, recently facebook upgraded to IPv6 and my network does'nt support IPv6 so all of my calls started returning Host is unreachable error, I searched on facebook bugs and found that we can still use force the requests to facebook to use IPv4 using CURL CURLOPT_IPRESOLVE.

现在,当我尝试使用 curl 向 Facebook Graph API 发送请求时,我得到了注意:使用未定义的常量 CURLOPT_IPRESOLVE - 假设为 'CURLOPT_IPRESOLVE'

Now when I try to send request to Facebook Graph API using curl I get Notice: Use of undefined constant CURLOPT_IPRESOLVE - assumed 'CURLOPT_IPRESOLVE'

我想知道如何启用对这个常量的支持,或者如何在 php 中禁用 IPv6 支持,以便我可以使用 IPv4 向 Facebook Graph API 发送请求.

I want to know how can I enable support for this constant or how can I disable IPv6 support in php so that I can send request to Facebook Graph API using IPv4.

我的代码是

    $url = ("https://graph.facebook.com/me/access_token?tokrn");
        $c = curl_init();
        curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($c, CURLOPT_URL, $url);
        curl_setopt($c, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); 
        $contents = curl_exec($c);
        $err  = curl_getinfo($c,CURLINFO_HTTP_CODE);
        curl_close($c);

谢谢

推荐答案

检查 curl 版本

Check you curl version

CURLOPT_IPRESOLVE 从 curl 7.10.8 开始可用

CURLOPT_IPRESOLVE is available since curl 7.10.8

试试这个示例代码来测试

Try this sample code to test

<?php

    $version = curl_version();

// These are the bitfields that can be used 
// to check for features in the curl build
$bitfields = Array(
            'CURL_VERSION_IPV6', 
            'CURLOPT_IPRESOLVE'
            );


foreach($bitfields as $feature)
{
    echo $feature . ($version['features'] & constant($feature) ? ' matches' : ' does not match');
    echo PHP_EOL;
}

仅供参考:http://gcov.php.net/PHP_5_3/lcov_html/curl/interface.c.gcov.php

这篇关于PHP 卷曲 CURLOPT_IPRESOLVE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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