2011-11-23 109 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