2013-06-27 35 views
0

所以我張貼數據到另一個系統和我想檢索「重定向URL」,該系統響應回來,2秒後重定向用戶,但我得到:我收到「請求的URL未找到...」與cURL錯誤。有任何想法嗎?

請求的URL /somescript.aspx在這個服務器上沒找到。

任何想法我做錯了什麼?或者還有其他什麼玩法?

<?php 
$strURL = 'http://someplace.com/somescript.aspx'; 
$fields_string = implode('&', (array)$_SESSION['apply']); 

$resURL = curl_init(); 
curl_setopt($resURL, CURLOPT_URL, $strURL); 
curl_setopt($resURL, CURLOPT_POST, true); 
curl_setopt($resURL, CURLOPT_POSTFIELDS, $fields_string); 
curl_setopt($resURL, CURLOPT_HEADER, TRUE); 
curl_setopt($resURL, CURLOPT_FOLLOWLOCATION, FALSE); 
$response = curl_exec($resURL); 
$RedirectLocation = curl_getinfo($resURL, CURLINFO_EFFECTIVE_URL); 

unset($_SESSION['apply']); ?> 
<script type="text/javascript"> 
$(function() { 
    setTimeout(function() { 
     window.location.href = "<?php echo $RedirectLocation; ?>"; 
    }, 2000) 
}); 
</script> 

回答

0

所以你想要檢索301/302重定向目標,但實際上並沒有遵循它?將CURLOPT_RETURNTRANSFER設置爲true,並將Location:標題解析爲響應。

要明白我的意思改變你的代碼,以這樣的:如果你不設置捲曲跟隨重定向

curl_setopt($resURL,CURLOPT_RETURNTRANSFER); 
$response = curl_exec($resURL); 
echo $repsonse 

IIRC CURLINFO_EFFECTIVE_URL不會改變。

+0

太好了。我會嘗試。但是,將修復/更正「請求的網址」錯誤? – FrankO

相關問題