代码之家  ›  专栏  ›  技术社区  ›  Kim Stacks

我有一个curl,它可以在本地主机上运行,但不能在实时网站上运行。我不明白为什么

  •  1
  • Kim Stacks  · 技术社区  · 16 年前

    http://www.bata.com.sg

    我用其他域名进行了测试,比如 http://www.yahoo.com.sg

    http://w-shadow.com/blog/2007/08/02/how-to-check-if-page-exists-with-curl/ 逐字逐句。

    curl_exec($ch);

    我得到这个是因为curl_error无法解析主机“www.bata.com.sg”

    3 回复  |  直到 16 年前
        1
  •  5
  •   Anti Veeranna    16 年前

    1. 它连接到IP地址www.bata.com.sg解析为-194.228.50.32

    <?php
    
    // this is the IP address that www.bata.com.sg resolves to
    $server = '194.228.50.32';
    $host   = 'www.bata.com.sg';
    
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $server);
    
    /* set the user agent - might help, doesn't hurt */
    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
    
    
    /* try to follow redirects */
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    
    /* timeout after the specified number of seconds. assuming that this script runs
    on a server, 20 seconds should be plenty of time to verify a valid URL.  */
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15);
    curl_setopt($ch, CURLOPT_TIMEOUT, 20);
    
    
    $headers = array();
    $headers[] = "Host: $host";
    
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
    
    curl_setopt($ch, CURLOPT_VERBOSE, true);
    
    /* don't download the page, just the header (much faster in this case) */
    curl_setopt($ch, CURLOPT_NOBODY, true);
    curl_setopt($ch, CURLOPT_HEADER, true);
    
    $response = curl_exec($ch);
    curl_close($ch);
    
    var_dump($response);
    
        2
  •  0
  •   Kim Stacks    16 年前

    在使用这个网站时,我被告知bata.com.sg的名称服务器有问题

    http://www.intodns.com/bata.com.sg

        3
  •  -1
  •   RageZ    16 年前

    file_get_contents('http://www.yahoo.com.sg');
    
    推荐文章