2010-03-20 53 views
3

我試圖加載圖表作爲圖像在安全的網站。通過https谷歌的圖表圖像的一個例子是這樣的:通過HTTPS的谷歌圖表

http://www.google.com/chart?cht=lc&chs=200x125&chd=s:helloWorld

的問題是,雖然您可以直接點擊該鏈接加載這樣的圖像,你可以不包括它像在圖像你的頁面。它只是不會加載。

任何想法如何繞過?或一般使用PHP的解決方案?

+0

其實,如果我點擊該鏈接,Google會返回一個「錯誤請求」頁面。但是,如果我通過http(如果它爲你工作,清除你的緩存,然後再試一次!),它會起作用。 – MikeyB 2010-03-20 06:36:41

+0

@MikeyB和@ swt83,修改鏈接的問題。 – 2010-03-20 06:38:43

回答

5

谷歌不支持圖表通過HTTPS ...

我有同樣的問題。

http://groups.google.com/group/google-chart-api/browse_thread/thread/95c463d88cf3cfe4

可以但是使用PHP或.NET創建一個代理頁面通過HTTPS連接來過濾谷歌的HTTP鏈接來解決這樣的問題。

下面是我用一個簡單的PHP代理...

<?php 
    // PHP Proxy 
    // Loads a XML from any location. Used with Flash/Flex apps to bypass security restrictions 
    // Author: Paulo Fierro 
    // January 29, 2006 
    // usage: proxy.php?url=http://mysite.com/myxml.xml 

    $session = curl_init($_GET['url']);     // Open the Curl session 
    curl_setopt($session, CURLOPT_HEADER, false);   // Don't return HTTP headers 
    curl_setopt($session, CURLOPT_RETURNTRANSFER, true); // Do return the contents of the call 
    $xml = curl_exec($session);       // Make the call 
    header("Content-Type: text/xml");     // Set the content type appropriately 
    echo $xml;  // Spit out the xml 
    curl_close($session); // And close the session 
?> 
+1

Google圖表現在可用於HTTPS:http://stackoverflow.com/questions/2482168/google-charts-over-https/4739924#4739924 – 2011-06-28 21:54:08

4

看起來像谷歌阻止https請求具有引用:標頭集的圖表。

[tla ~]$ curl 'http://www.google.com/chart?cht=lc&chs=200x125&chd=s:helloWorld' 2>/dev/null | file - 
/dev/stdin: PNG image, 200 x 125, 8-bit/color RGB, non-interlaced 
[tla ~]$ curl 'https://www.google.com/chart?cht=lc&chs=200x125&chd=s:helloWorld' 2>/dev/null | file - 
/dev/stdin: PNG image, 200 x 125, 8-bit/color RGB, non-interlaced 
[tla ~]$ curl -H 'Referer: http://stackoverflow.com' 'http://www.google.com/chart?cht=lc&chs=200x125&chd=s:helloWorld' 2>/dev/null | file - 
/dev/stdin: PNG image, 200 x 125, 8-bit/color RGB, non-interlaced 
[tla ~]$ curl -H 'Referer: http://stackoverflow.com' 'https://www.google.com/chart?cht=lc&chs=200x125&chd=s:helloWorld' 2>/dev/null | file - 
/dev/stdin: ASCII HTML document text, with very long lines 
+1

它引起了我的注意,我喜歡使用經驗方法;) – MikeyB 2010-03-20 06:59:21

8

它看起來像谷歌終於更新了自己的API,允許HTTPS。您只需將主機名切換到chart.googleapis.com,以便基本URL類似於https://chart.googleapis.com/chart,並且工作正常。請享用!