Zend_Uri_Http:使用Google Chart URI时提供的URI无效?

时间:2010-08-16 16:14:08

标签: zend-framework google-visualization zend-http-client

我的应用使用Google图表并使用HTTPS。我需要将Google图表显示为“安全”图像,否则Internet Explorer会抱怨显示不安全的内容。所以,我试图使用Zend_Http_Client请求下载它们(然后链接到本地​​文件),但我似乎无法做到。

URI应该有效,因为我可以点击此链接并查看图像:

http://chart.apis.google.com/chart?chs=250x150&cht=bvg&chds=0,19&chd=t:19&chxt=x,y&chxl=0:|2009&chxr=1,0,19&chf=bg,s,F2F0E1

这是我正在使用的代码:

$chartUrl = 'http://chart.apis.google.com/chart?chs=250x150&cht=bvg&chds=0,19&chd=t:19&chxt=x,y&chxl=0:|2009&chxr=1,0,19&chf=bg,s,F2F0E1';
$client = new Zend_Http_Client($chartUrl, array('maxredirects' => 0, 'timeout' => 30));
$response = $client->request();

我做错了什么?还有另一种方法可以达到这个目的吗?

变通

由于Google Chart URI使用“无效”字符,因此在构建Zend_Uri时验证失败。这是我为了下载Google图表而必须做的事情。

/**
 * Returns the URL of the Google chart image that has been downloaded and stored locally. If it has not been downloaded yet, it will be download.
 * @param string $chartUrl
 * @return string
 */
protected function _getLocalImageUrl($chartUrl)
{
    $savePath = realpath(APPLICATION_PATH . '/../public/Resources/google-charts/');
    $hashedChartUrl = md5($chartUrl);
    $localPath = "$savePath/$hashedChartUrl";

    if (!file_exists($localPath)) {
        exec("wget -O \"$localPath\" \"$chartUrl\"");
    }

    return "/Resources/google-charts/$hashedChartUrl";
}

1 个答案:

答案 0 :(得分:0)

尝试:$chartUrl = 'http://chart.apis.google.com/chart?chs=250x150&cht=bvg&chds=0,19&chd=t%3A19&chxt=x,y&chxl=0%3A|2009&chxr=1,0,19&chf=bg,s,F2F0E1';

[编辑] 正如评论中所提到的,urlencode没有解决问题,但用冒号替换冒号确实。

相关问题