我得到了“;找不到请求的URL";cURL错误.任何想法


I am getting "Requested URL not found..." error with cURL. Any ideas?

所以我将数据发布到另一个系统,并希望检索系统响应的"重定向url",并在2秒钟后重定向用户,但我得到:

在此服务器上找不到请求的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>

所以您想要检索301/302重定向目标,但实际上并没有遵循它?将CURLOPT_RETURNTRANSFER设置为true,并解析响应中的Location:标头。

要了解我的意思,请将您的代码更改为:

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

如果不将curl设置为遵循重定向,IIRC CURLINFO_EFFECTIVE_URL将不会更改。