1

cURL 経由で YQL を呼び出そうとすると、次のエラーが発生します。

サポートされていない HTTP バージョン 説明: Web サーバー "engine1.yql.vip.bf1.yahoo.com" は、サポートされていないバージョンの HTTP プロトコルを使用しています。

以下は使用されたコードです

    // URL
    $URL = "https://query.yahooapis.com/v1/public/yql?q=select * from html where url=\"http://www.infibeam.com/Books/search?q=9788179917558\" and xpath=\"//span[@class='infiPrice amount price']/text()\"&format=json";

    // set url
    curl_setopt($ch, CURLOPT_URL, $URL);

    //return the transfer as a string
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

    // $output contains the output string
    $output = curl_exec($ch);

    // close curl resource to free up system resources
    curl_close($ch);

    echo $output;

?>

ブラウザから同じ URL を呼び出しても問題なく動作する

https://query.yahooapis.com/v1/public/yql?q=select * html where url="http://www.infibeam.com/Books/search?q=9788179917558" and xpath="// span[@class='infiPrice 金額']/text()"&format=json

誰かがコードのどこが間違っているか教えてもらえますか?

4

2 に答える 2

1

さて、私は得た..問題はhttpsにありました。デバッグに次のスニペットを使用

if (false === ($data = curl_exec($ch))) {
        die("Eek! Curl error! " . curl_error($ch));
    }

デフォルトで SSL 証明書を受け入れるように、以下のコードを追加しました。

$options = array(CURLOPT_URL => $URL,
        CURLOPT_HEADER => "Content-Type:text/xml",
        CURLOPT_SSL_VERIFYPEER => 0,
        CURLOPT_RETURNTRANSFER => TRUE

    );

完全なコードはこちら

<?php
    // create curl resource
    $ch = curl_init();

    // URL
    $q = urlencode("select * from html where url=\"http://www.infibeam.com/Books/search?q=9788179917558\" and xpath=\"//span[@class='infiPrice amount price']/text()\"");
    $URL = "https://query.yahooapis.com/v1/public/yql?q={$q}&format=json";

    echo "URL is ".$URL;
    $ch = curl_init();

    //Define curl options in an array
    $options = array(CURLOPT_URL => $URL,
        CURLOPT_HEADER => "Content-Type:text/xml",
        CURLOPT_SSL_VERIFYPEER => 0,
        CURLOPT_RETURNTRANSFER => TRUE

    );

    //Set options against curl object
    curl_setopt_array($ch, $options);

    //Assign execution of curl object to a variable
    $data = curl_exec($ch);
    echo($data);

    //Pass results to the SimpleXMLElement function
    //$xml = new SimpleXMLElement($data);

    echo($data);

    if (false === ($data = curl_exec($ch))) {
        die("Eek! Curl error! " . curl_error($ch));
    }

    if (200 !== (int)curl_getinfo($ch, CURLINFO_HTTP_CODE)) {
        die("Oh dear, no 200 OK?!");
    }

    //Close curl object
            curl_close($ch);

?>

于 2014-04-26T14:41:54.630 に答える