【问题标题】:Getting XML from URL with CURL stopped working after PHP Update使用 CURL 从 URL 获取 XML 在 PHP 更新后停止工作
【发布时间】:2018-05-26 03:27:19
【问题描述】:

我使用以下函数从受密码保护的 https url 接收 xml 文件。

function get_fcontent( $url,  $javascript_loop = 0, $timeout = 5 ) {

    $url = str_replace( "&", "&", urldecode(trim($url)) );
    $cookie = tempnam ("/tmp", "CURLCOOKIE");
    $ch = curl_init();

    curl_setopt( $ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; rv:1.7.3) Gecko/20041001 Firefox/0.10.1" );
    curl_setopt( $ch, CURLOPT_URL, $url );
    curl_setopt( $ch, CURLOPT_COOKIEJAR, $cookie );
    curl_setopt( $ch, CURLOPT_ENCODING, "" );
    curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
    curl_setopt( $ch, CURLOPT_AUTOREFERER, true );
    curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );    # required for https urls
    curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, $timeout );
    curl_setopt( $ch, CURLOPT_TIMEOUT, $timeout );
    curl_setopt( $ch, CURLOPT_MAXREDIRS, 10 );
    $content = curl_exec( $ch );
    $response = curl_getinfo( $ch );
    curl_close ( $ch );

    if ($response['http_code'] == 301 || $response['http_code'] == 302) {
        ini_set("user_agent", "Mozilla/5.0 (Windows; U; Windows NT 5.1; rv:1.7.3) Gecko/20041001 Firefox/0.10.1");

        if ( $headers = get_headers($response['url']) ) {
            foreach( $headers as $value ) {
                if ( substr( strtolower($value), 0, 9 ) == "location:" )
                    return get_url( trim( substr( $value, 9, strlen($value) ) ) );
            }
        }
    }

    if (    ( preg_match("/>[[:space:]]+window\.location\.replace\('(.*)'\)/i", $content, $value) || preg_match("/>[[:space:]]+window\.location\=\"(.*)\"/i", $content, $value) ) && $javascript_loop < 5) {
        return get_url( $value[1], $javascript_loop+1 );
    } else {
        return array( $content, $response );
    }
}

一切正常,直到我们的服务器获得 php 更新到版本:7.0.22

在那之后我无法再收到 xml 文件了。我只是得到一个空洞的回应。 有人知道为什么吗?

编辑:我不知道之前安装了哪个 php 版本,我们无法降级。

【问题讨论】:

  • 查看您服务器的错误日志 - 是否有任何可能连接的错误?
  • 只是警告我的变量(里面有 xml 数据)是空的,没有别的
  • 好的,然后开始调试它:该代码的哪些部分仍然有效,从什么时候停止?

标签: php xml curl


【解决方案1】:

再次安装与您的版本兼容的php-curl。如果您是 linux,请检查此答案 How do I install the ext-curl extension with PHP 7?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-09-03
    • 2019-06-13
    • 2016-11-03
    • 1970-01-01
    • 1970-01-01
    • 2011-07-21
    • 2019-02-27
    • 1970-01-01
    相关资源
    最近更新 更多