2013-01-08 86 views
0

我有以下代碼:CURL響應代碼是200,而不是302

$curl=curl_init();  
    $allowAppPostPArams = 'utf8=%E2%9C%93&authenticity_token='.$this->authToken.'&permissions=manage_likes%2Cmanage_relationships%2Cmanage_comments%2C&response_type=code&app_id=d2a4fc6d2751&redirect_uri=http%3A%2F%2FsocialCamFollower%2Findex.php&choice=authorize&commit=Authorize'; 
    curl_setopt($curl, CURLOPT_POSTFIELDS, $allowAppPostPArams); 
    curl_setopt($curl, CURLOPT_POST, 1); 

    curl_setopt($curl, CURLOPT_COOKIEFILE, $cookie_file); 
    curl_setopt($curl, CURLOPT_COOKIEJAR, $cookie_file); 

    curl_setopt($curl, CURLOPT_URL, 'https://socialcam.com/oauth/form_submit');   
    curl_setopt($curl, CURLOPT_REFERER, $urlAppPage); 

    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); 
    curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:17.0) Gecko/20100101 Firefox/17.0'); 
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); 

    curl_close($curl); 

瀏覽器的請求: enter image description here

捲曲LOG curl log

問題:爲什麼CURL顯示200而不是302?

服務器:MAMP,Apache2,php5.3.14。安全模式& open_basedir未設置。

+0

提到什麼是200和302的輸出?它是一個響應代碼嗎? – Sahal

+0

什麼是cron?.. – Sahal

+0

我的錯誤是CURL。固定在帖子 – Joeeee

回答

1

使用此

curl_setopt($ch, CURLOPT_HEADERFUNCTION, 'read_header'); 
... 
curl_exec($ch); 
... 
function read_header($curl, $header) { 
    echo $header; 
    return strlen($header); 
} 

隨着CURLOPT_FOLLOWLOCATION使你應該得到像

HTTP/1.0 301 Moved Permanently 
Date: Fri, 20 Apr 2012 11:26:37 GMT 
Server: Apache 
Location: http://www.spiegel.de/ 
Content-Length: 230 
Content-Type: text/html; charset=iso-8859-1 
X-Cache: MISS from lnxp-3968.srv.mediaways.net 
X-Cache-Lookup: MISS from lnxp-3968.srv.mediaways.net:91 
Via: 1.0 lnxp-3968.srv.mediaways.net (squid/3.1.4) 
Connection: close 

HTTP/1.0 200 OK 
Date: Fri, 20 Apr 2012 11:25:38 GMT 
Server: Apache-Coyote/1.1 
X-Powered-By: Servlet 2.4; JBoss-4.0.3SP1 (build: CVSTag=JBoss_4_0_3_SP1 date=200510231054)/Tomcat-5.5 
Cache-Control: max-age=120 
Expires: Fri, 20 Apr 2012 11:27:38 GMT 
X-Host: lnxp-2885 
X-Robots-Tag: index, follow, noarchive 
Content-Type: text/html;charset=ISO-8859-1 
Content-Length: 161305 
Vary: Accept-Encoding 
Age: 59 
X-Cache: HIT from lnxp-3954.srv.mediaways.net 
X-Cache-Lookup: HIT from lnxp-3954.srv.mediaways.net:90 
Via: 1.1 www.spiegel.de, 1.0 lnxp-3954.srv.mediaways.net (squid/3.1.4) 
Connection: close 
+0

已經返回HTTP/1.1 200 OK Cache-Control:no-cache Content-Type:text/html; charset = utf-8日期:2013年1月8日星期二11:25:24 GMT服務器:nginx設置Cookie:_socialcam_session = BAh7BkkiD3Nlc3Npb25faWQGOgZFRiIlZGM4ZDAzZDgwZDFhMDAzYTU5MWY1ZTk5YmJhYjdhNGM%3D - 45716f28f25ab264877d6d5eee73c300418fded2;域= .socialcam.com;路徑= /; HttpOnly Status:200 OK Vary:Accept-Encoding X-Runtime:0.039598 X-UA-Compatible:IE = Edge,chrome = 1內容長度:1連接:keep-alive – Joeeee