2011-11-23 104 views
3

这是命令行:转换卷曲命令行PHP

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; 

回答

1

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

试试这个行:

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

是的,我已经试过这种方式,以及=而不是:,谢谢。我想我可能会调用错误的头部类型的调用,但我不知道还有什么其他用途。 – iamdamnsam

0

,也许你可以检查CURLOPT_SSL_VERIFYPEERCURLOPT_SSL_VERIFYHOST假以防止类似问题的任何SSL证书....还什么错误代码,你得到像403访问禁止...有关错误或基于详细日志的任何信息将是非常有用的...希望我的建议有所帮助...

干杯!

+0

我给了他们一个尝试,还是一样的。这是错误,虽然它在命令行上完美工作,但它只是没有验证{ “error”:{ “errors”:[ “domain”:“global”, “reason”:“authError” , “消息”: “无效凭证”, “的locationType”: “首标”, “位置”: “授权” } ], “代码”:401, “消息”: “无效凭证” } } – iamdamnsam

+0

@ user1062332猜你可以检查[这](http://stackoverflow.com/questions/1304974/set-authorization-header-using-php-and-curl)可能会证明对你的情况有用 – optimusprime619

+0

谢谢,但没有帮助我。我已经尝试过在命令行版本中使用的每一个组合,但它仍然不起作用。 – iamdamnsam