J'essaie de faire une demande de publication avec php et curl. Voici mon codephp + curl impossible de définir la méthode de publication
//PHP 5.3.5 and curl: 7.18.2
$ch = curl_init();
if(!empty($save_cookie)){
curl_setopt($ch, CURLOPT_COOKIEJAR, $save_cookie);
curl_setopt($ch, CURLOPT_COOKIEFILE, $save_cookie);
}else{
curl_setopt($ch, CURLOPT_COOKIE, $cookie);
}
curl_setopt($ch, CURLOPT_REFERER, $referer);
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt($ch, CURLOPT_URL, 'http://localhost/post.php');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $pars);
curl_setopt($ch, CURLOPT_HEADER, $header);
curl_setopt($ch, CURLOPT_NOBODY, !$body);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$postResult = curl_exec($ch);
if (curl_errno($ch)) {
return false;
}
curl_close($ch);
return $postResult;
En http://localhost/post.php, j'écris
print_r($_SERVER);
Le retour de résultat de boucle est toujours
[REQUEST_METHOD] => GET
Bizarre. Pouvez-vous poster une trace de paquet? (Utiliser Wireshark ou similaire.) De plus, PHP est-il appelé via CGI ou comme un module? Quel serveur web? Voir aussi http://redmine.lighttpd.net/issues/1472. Je soupçonne que si vous établissiez des données POST et regardiez '$ _POST' dans post.php, vous verriez vos données. – Brad
J'utilise apache + fastcgi. Je suis aussi imprimer $ _POST mais c'est vide – complez