Voici mon client http en php pour faire des requêtes post avec des cookies inclus :
function http_login_client($url, $params = "", $cookies_send = "" ){
// Vars
$cookies = array();
$headers = getallheaders();
// Perform a http post request to $ur1 using $params
$ch = curl_init($url);
$options = array( CURLOPT_POST => 1,
CURLINFO_HEADER_OUT => true,
CURLOPT_POSTFIELDS => $params,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_HEADER => 1,
CURLOPT_COOKIE => $cookies_send,
CURLOPT_USERAGENT => $headers['User-Agent']
);
curl_setopt_array($ch, $options);
$response = curl_exec($ch);
/// Info DEBUG echo $response ; var_dump (curl_getinfo($ch)) ; ///
// Parse response and read cookies
preg_match_all('/^Set-Cookie: (.*?)=(.*?);/m', $response, $matches);
// Build an array with cookies
foreach( $matches[1] as $index => $cookie )
$cookies[$cookie] = $matches[2][$index];
return $cookies;
} // end http_login_client
0 votes
Cette adresse peut être utile. helloacm.com/curl
1 votes
Vous pouvez l'utiliser pour tester run-node.com/now-use-curl-with-http-echo-com