cURL'格式错误的网址' - php

这个网址

'http://profile.myspace.com/index.cfm?fuseaction=user.viewProfile&friendID=39726387'

在浏览器中可以很好地工作,但是cURL返回错误3(URL格式错误)。

有什么想法可以解决吗?

编辑:

cURL代码:

function get_web_page( $url )
{
    $options = array(
        CURLOPT_RETURNTRANSFER => true,     // return web page
        CURLOPT_HEADER         => false,    // don't return headers
        CURLOPT_FOLLOWLOCATION => true,     // follow redirects
        CURLOPT_ENCODING       => "",       // handle all encodings
        CURLOPT_USERAGENT      => "spider", // who am i
        CURLOPT_AUTOREFERER    => true,     // set referer on redirect
        CURLOPT_CONNECTTIMEOUT => 120,      // timeout on connect
        CURLOPT_TIMEOUT        => 120,      // timeout on response
        CURLOPT_MAXREDIRS      => 10,       // stop after 10 redirects
    );

    $ch      = curl_init( $url );
    curl_setopt_array( $ch, $options );
    $content = curl_exec( $ch );
    $err     = curl_errno( $ch );
    $errmsg  = curl_error( $ch );
    $header  = curl_getinfo( $ch );
    curl_close( $ch );

    if (!$errmsg =='') {die($err.':'.$errmsg);} 
    return $content;
}

参考方案

我在运行时得到页面的输出

curl http://profile.myspace.com/index.cfm?fuseaction=user.viewProfile&friendID=39726387

这也适用于我:

$ch = curl_init('http://profile.myspace.com/index.cfm?fuseaction=user.viewProfile&friendID=39726387');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$out = curl_exec($ch);
curl_close($ch);

echo $out;

编辑:刚刚尝试过发布您的代码,它对我来说很好。也许您传递给get_web_page()的字符串是错误的?

我如何通过cURL在php中发布JSON对象 - php

如何通过php中的cURL将JSON对象发布到Web服务?我有一个数组$data = array('username'=>'abc','password'=>'pass'); 我要调用的Web服务接受JSON对象,如果我使用json_encode将$ data转换为J…

检索通过curl传递的用户名,密码参数 - php

我正在尝试使用curl将用户名和密码参数发送到url,我想检索它们。我将参数发送到页面,如下所示:<?php $curl = curl_init('http://localhost/sample.php'); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($cu…

PHP strtotime困境 - php

有人可以解释为什么这在我的服务器上输出为true吗?date_default_timezone_set('Europe/Bucharest'); var_dump( strtotime('29.03.2015 03:00', time()) === strtotime('29.03.2015 04:00�…

PHP-全局变量的性能和内存问题 - php

假设情况:我在php中运行一个复杂的站点,并且我使用了很多全局变量。我可以将变量存储在现有的全局范围内,例如$_REQUEST['userInfo'],$_REQUEST['foo']和$_REQUEST['bar']等,然后将许多不同的内容放入请求范围内(这将是适当的用法,因为这些数据指的是要求自…

php-casperjs获取内部文本 - php

我正在为casperjs使用php包装器-https://github.com/alwex/php-casperjs我正在网上自动化一些重复的工作,我需要访问一个项目的innerText,但是我尚不清楚如何从casperjs浏览器访问dom。我认为在js中我会var arr = document.querySelector('label.input…