将cURL命令行转换为PHP

时间:2011-11-23 16:41:26

标签: php curl command-line

这是命令行:

curl --silent --header "Authorization: MyLogin auth=xxxxxxxxxxxxxxxxxxx" "https://www.myweb.com/"

我这就是我所拥有的(尝试使用标题的各种变体)

    $ch = curl_init();

    curl_setopt($ch, CURLOPT_URL, "https://www.myweb.com");

    curl_setopt($ch,CURLOPT_HTTPHEADER,array('Authorization: MyLogin','auth: xxxxxxxxxxxxxxxxxxx'));

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

    $output = curl_exec($ch);

    curl_close($ch);

    echo $output;

我认为我搞砸了标题部分,任何帮助都会非常感激。感谢。

添加*这就是我实际使用的内容

http://code.google.com/apis/gdata/articles/using_cURL.html#authenticating

我刚刚重写了它,现在它有效,这就是我所拥有的:

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HEADER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: GoogleLogin auth=$authCode"));
    //curl_setopt($ch, CURLINFO_HEADER_OUT, true); // for debugging the request
    //var_dump(curl_getinfo($ch,CURLINFO_HEADER_OUT)); //for debugging the request
    $response = curl_exec($ch);
    curl_close($ch);

    echo $response;

2 个答案:

答案 0 :(得分:1)

我认为Authorization标题应该作为一个字符串发送,而不是作为2个标题值发送。

请尝试使用此行:

curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: MyLogin auth: xxxxxxxxxxxxxxxxxxx'));

答案 1 :(得分:0)

也许您可以检查 CURLOPT_SSL_VERIFYPEER CURLOPT_SSL_VERIFYHOST false以防止任何SSL证书之类的问题....还会出现像403访问禁止的错误代码...关于错误或基于详细日志的任何信息都会非常有用......希望我的建议有所帮助......

干杯!!

相关问题