PHP cURL doesn't see the /etc/hosts file

前端 未结 2 539
抹茶落季
抹茶落季 2021-02-08 12:53

I\'m having troubles on making the PHP cURL library recognize the alias I created in my /etc/hosts file.

This is what I have in my /etc/hosts f

相关标签:
2条回答
  • 2021-02-08 13:39

    Solved using this url "http://192.168.0.20/" instead of "http://www.example.dev"

    Also the "Host" header is needed...

    $header = array
    (
        "Host: www.example.dev", // IMPORTANT
        "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
        "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3",
        "Accept-Encoding: gzip,deflate,sdch",
        "Accept-Language: it-IT,it;q=0.8,en-US;q=0.6,en;q=0.4",
        "Cache-Control: max-age=0",
        "Connection: keep-alive",
    );
    
    curl_setopt($this->ch, CURLOPT_URL, 'http://192.168.0.20/');
    curl_setopt($this->ch, CURLOPT_HTTPHEADER, $header);
    
    0 讨论(0)
  • 2021-02-08 13:55

    You probably run PHP on that apache server, and there you don't have the hosts file entry.

    0 讨论(0)
提交回复
热议问题