Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy am I getting HTTP_CODE 0 from curl?
    primarykey
    data
    text
    <p>I have been using curl with PHP for a while. Today I've been trying to fetch <a href="http://www.webhostingstuff.com/category/Best-Hosting.html" rel="noreferrer">http://www.webhostingstuff.com/category/Best-Hosting.html</a> and I keep getting http code 0, which is new to me.</p> <p>I set the headers</p> <pre><code>$s-&gt;headers = array( "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.1", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "Accept-Language: en-gb,en;q=0.5", "Accept-Encoding: gzip, deflate", "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7", "Keep-Alive: 115", "Connection: keep-alive", "Referer: https://google.com" ); </code></pre> <p>and I have a cookie file (which has nothing in it when the script finishes loading)</p> <p>Here's the curl function </p> <pre><code>function fetch($url, $username='', $data='', $proxy=''){ $ch = curl_init(); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, true); if(isset($proxy)) { curl_setopt($ch,CURLOPT_TIMEOUT,30); curl_setopt($ch, CURLOPT_PROXY, $proxy); curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1); curl_setopt($ch, CURLOPT_PROXYPORT, $proxy); curl_setopt($ch, CURLOPT_PROXYUSERPWD, 'proxyadmin:parola'); } curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FRESH_CONNECT,true); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.1"); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_MAXREDIRS, 5); if(!empty($username)) { curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie/{$username}.txt"); curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie/{$username}.txt"); } curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); if (is_array($data) &amp;&amp; count($data)&gt;0) { curl_setopt($ch, CURLOPT_POST, true); $params = http_build_query($data); curl_setopt($ch, CURLOPT_POSTFIELDS, $params); } if (is_array($this-&gt;headers) &amp;&amp; count($this-&gt;headers)&gt;0){ curl_setopt($ch, CURLOPT_HTTPHEADER, $this-&gt;headers); } $this-&gt;result = curl_exec($ch); $curl_info = curl_getinfo($ch); $header_size = $curl_info["header_size"]; $this-&gt;headers = substr($this-&gt;result, 0, $header_size); $this-&gt;http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); $this-&gt;error = curl_error($ch); curl_close($ch); } </code></pre> <p>I've also tried to execute via SSH from a different server(in case it's IP blocked) </p> <pre> [brian@ip-184-168-22-244 ~]$ curl -url http://www.webhostingstuff.com/addcomments/5ite.html Enter host password for user 'rl': curl: (7) couldn't connect to host [brian@ip-184-168-22-244 ~]$ </pre> <p>How might I resolve this?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload