title: How to resolve cURL Error (7): couldn't connect to host?
body: <p>I send an item code to a web service in xml format using cUrl(php). I get the correct response in localhost, but when do it server it shows </p>
  
  <blockquote>
    <p>cURL Error (7): couldn't connect to host</p>
  </blockquote>
  
  <p>And here's my code:</p>
  
  <pre><code>function xml_post($post_xml, $url)
  {
      $user_agent = $_SERVER['HTTP_USER_AGENT'];
  
      $ch = curl_init();    // initialize curl handle
      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
      curl_setopt($ch, CURLOPT_URL, $url); 
      curl_setopt($ch, CURLOPT_FAILONERROR, 1);          
      curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);    
      curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); 
      curl_setopt($ch, CURLOPT_TIMEOUT, 50); 
      curl_setopt($ch, CURLOPT_POSTFIELDS, $post_xml); 
      curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
  //  curl_setopt($ch, CURLOPT_PORT, $port);          
  
      $data = curl_exec($ch);
      $curl_errno = curl_errno($ch);
      $curl_error = curl_error($ch);
      if ($curl_errno &gt; 0) {
              echo "cURL Error ($curl_errno): $curl_error\n";
      } else {
              echo "Data received\n";
      }
      curl_close($ch);
  
      echo $data;
  }
  </code></pre>
  
  <p>I send the item code to the tally and fetch the details from it. I tried using both the versions php 4+ and php5+, nothing works out Any solution.</p>