2010-12-07 3 views
0

J'essaie d'appeler un site sur localhost d'un autre également sur localhost en utilisant CURL en PHP. (Il est un test)appel localhost site à partir d'un autre site localhost en utilisant PHP CURL

J'utilise windows 7

Les deux sont mis en place dans le fichier hôte et fonctionne très bien si on y accède directement

je reçois une erreur 404. Si j'appelle un site sur le web alors ça revient bien.

N'est-ce pas possible?

protected function get($url) 
{ 
    $curl = curl_init($url); 
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); 
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0); 
    $response = curl_exec($curl); 
    $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); 
    if($httpCode != 200) 
     throw new CHttpException($httpCode, 'Curl Error : ' . $response); 
    return $response; 
} 
+0

utilisez-vous vhosts? – stillstanding

+0

peut-être une faute de frappe dans votre URL? – Tokk

+0

@stillstanding Oui. Tout fonctionne très bien depuis un navigateur – SystemicPlural

Répondre

1

Puisque vous définissez les options SSL, vous utilisez probablement https. Cependant, sous Windows, vous devez indiquer à cURL où trouver le (s) certificat (s). Essayez curl_setopt($curl, CURLOPT_CAINFO, 'C:\path\to\curl-ca-bundle.crt');.

+0

Merci pour le conseil. J'en aurai besoin, mais j'ai juste essayé de commenter la ligne SSL (s!) Pour voir si c'était le cas, malheureusement pas. – SystemicPlural

Questions connexes