当cURLing相同的服务器时找不到404 404

时间:2013-08-21 10:44:26

标签: php curl

我正在研究HTML2PS,它在旧服务器上工作正常,转移到新服务器,它停止工作。

我已经找到了一个问题,即我从服务器找不到我通过CURL访问的临时文件,但该文件可以从其他位置(例如我的本地计算机)获取

此网址可能在近期无法使用,因为我可能会删除此链接。

http://www.lapchi.com/new/temp_curl.php5

链接代码如下

<form method="post">


<input type="text" name="url" value="http://www.lapchi.com/new/uploads/temp/html_pdf/503_S_b7ku0sbn1i8g8ll06ra1pth332.html" size="90" />
<input type="submit" value="go">
</form>
<?php


set_time_limit(8888);

if($_POST){
$url = $_POST['url'];
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL,$url ); // this file is physically exist on server
curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; rv:1.7) Gecko/20040803 Firefox/0.9.3");
curl_setopt($curl, CURLOPT_HEADER, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

$response = curl_exec($curl);
if ($response === FALSE) {
    error_log(sprintf('Cannot open %s, CURL error is: %s',
            $url,
            curl_error($curl)));
    curl_close($curl);
    return null;
}

curl_close($curl);
preg_match('/^(.*?)\r\n\r\n(.*)$/s', $response, $matches);

$headers = array_slice(explode("\r\n", $matches[1]),1);
$content = $matches[2];


echo $content;

}

我不确定,为什么同一台服务器上的同一个文件无法通过CURL找到,但其他人可以通过CURL这个网址和此页面可以卷曲其他网址

3 个答案:

答案 0 :(得分:3)

重复:

  

Can I do a CURL request to the same server?

在你的应用程序服务器上已经存在的东西cURL是没有意义的。

答案 1 :(得分:1)

我会这样做:

    shell中的
  1. 运行curl http://www.lapchi.com/new/uploads/temp/html_pdf/503_S_b7ku0sbn1i8g8ll06ra1pth332.html
  2. 如果不起作用,则DNS设置一定有问题

答案 2 :(得分:0)

通过在/ etc / hosts文件中添加74.208.15.19 server.com www.server.com来解决它现在正在运行