1

freebase MQL ログイン サービスに問題があります。投稿リクエストを作成すると、freebase api がヘッダーを送り返し、それを分析して情報を取得します。

しかし、私が得ている唯一のヘッダーはHTTP/1.0 200 OK

コード

class myFreebaseClass {

....

function doLogin() {

echo $uri = "http://".$this->config['apiSandboxHost'].'/'.$this->config['apiLoginPath'].'username='.$this->config['apiLoginUser'].'&password='.$this->config['apiLoginPass'];

$ch = curl_init($uri);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADERFUNCTION, array(&$this,'readHeader'));
$output = curl_exec($ch);
curl_close($ch);

}

function readHeader($ch, $string)
{
    echo "Header: ".$string."<Br />";
    if(strpos($string, 'Set-Cookie') !== false) {
        $this->authCookies[] = str_replace('Set-Cookie: ', '', $string);
    }
    return true;
}

}

出力

http://sandbox.freebase.com/api/account/login?username=dXXXXX&password=XXXX
Header: HTTP/1.0 200 OK 

私は何を間違っていますか?ヘッダーを間違って取得していますか?

前もって感謝します!

4

2 に答える 2

2

それはreadHeader()機能の問題でした。私の例では、私は戻ってtrueいました。各ヘッダーの長さを返すと、すべてうまくいきました。例えば

function readHeader($ch, $string)
{
    $length = strlen($string);
    if(strpos($string, 'Set-Cookie') !== false) {
        $this->authCookies[] = str_replace('Set-Cookie: ', '', $string);
    }
    return $length;
}

これが他の誰かに役立つことを願っています!

于 2010-09-07T07:55:43.550 に答える
0

PHP の curl のバグのようです。次の行で同じ問題が発生しました。

function readHeader($ch, $string)
{
    echo "Header: ".$string."<Br />";
}

echo $uri = 'http://localhost/';

$ch = curl_init($uri);
curl_setopt($ch, CURLOPT_HEADER, 1);//this line can also be omitted
curl_setopt($ch, CURLOPT_HEADERFUNCTION, 'readHeader');
$output = curl_exec($ch);
curl_close($ch);

従来の方法でヘッダーの抽出を行う必要があります。

class myFreebaseClass {

....

function doLogin() {

    echo $uri = "http://".$this->config['apiSandboxHost'].'/'.$this->config['apiLoginPath'].'username='.$this->config['apiLoginUser'].'&password='.$this->config['apiLoginPass'];

    $ch = curl_init($uri);
    curl_setopt($ch, CURLOPT_HEADER, 1);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HEADERFUNCTION, array(&$this,'readHeader'));
    $output = curl_exec($ch);

    //extracting headers:
    $infos = curl_getinfo($ch);
    $headers = substr($output, 0, $infos['header_size']);
    $headers = explode("\n", $headers);
    //done extracting headers
    $output = substr($output, $infos['header_size']);

    foreach($headers as $header) {
        readHeader($ch, trim($header));
    }
    curl_close($ch);

    }

    function readHeader($ch, $string)
    {
        echo "Header: ".$string."<Br />";
        if(strpos($string, 'Set-Cookie') !== false) {
            $this->authCookies[] = str_replace('Set-Cookie: ', '', $string);
        }
        return true;
    }

}
于 2010-09-06T18:55:39.557 に答える