Answered by : fedele-cavaliere
<?php
$post = [ 'username' => 'user1', 'password' => 'passuser1', 'gender' => 1,
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.domain.com');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post));
$response = curl_exec($ch);
var_export($response);
Source : https://stackoverflow.com/questions/2138527/php-curl-http-post-sample-code | Last Update : Fri, 02 Apr 21
Answered by : rafael
// set post fields
$post = [ 'username' => 'user1', 'password' => 'passuser1', 'gender' => 1,
];
$ch = curl_init('http://www.example.com');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
// execute!
$response = curl_exec($ch);
// close the connection, release resources used
curl_close($ch);
// do anything you want with your response
var_dump($response);
Source : https://stackoverflow.com/questions/2138527/php-curl-http-post-sample-code | Last Update : Fri, 22 May 20
Answered by : amrinder-singh-bajwa
function &web_curl_http($url)
{ $c = curl_init(); curl_setopt( $c , CURLOPT_URL , $url); curl_setopt( $c , CURLOPT_USERAGENT, "Mozilla/5.0 (Linux Centos 7;) Chrome/74.0.3729.169 Safari/537.36"); curl_setopt( $c , CURLOPT_RETURNTRANSFER, true); curl_setopt( $c , CURLOPT_SSL_VERIFYPEER, false); curl_setopt( $c , CURLOPT_SSL_VERIFYHOST, false); curl_setopt( $c , CURLOPT_TIMEOUT, 10000); // 10 sec $data = curl_exec($c); curl_close($c); return $data;
}
Source : https://stackoverflow.com/questions/58674511/simple-php-curl-get-request-not-working-at-all | Last Update : Fri, 17 Jun 22
Answered by : k-e-h-rahat
<?php
$post = [ 'username' => 'user1', 'password' => 'passuser1', 'gender' => 1,
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.domain.com');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post));
$response = curl_exec($ch);
var_export($response);
Source : https://stackoverflow.com/questions/2138527/php-curl-and-http-post-example | Last Update : Mon, 26 Jun 23
Answered by : karan-mehta-8dc1x4jfp7we
$ch = curl_init();
$curlConfig = array( CURLOPT_URL => "http://www.example.com/yourscript.php", CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_POSTFIELDS => array( 'field1' => 'some date', 'field2' => 'some other data', )
);
curl_setopt_array($ch, $curlConfig);
$result = curl_exec($ch);
curl_close($ch);
Source : | Last Update : Wed, 10 Aug 22
Answered by : k-e-h-rahat
<?php $ch = curl_init(); $skipper = "luxury assault recreational vehicle"; $fields = array( 'penguins'=>$skipper, 'bestpony'=>'rainbowdash'); $postvars = ''; foreach($fields as $key=>$value) { $postvars .= $key . "=" . $value . "&"; } $url = "http://www.google.com"; curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_POST, 1); //0 for a get request curl_setopt($ch,CURLOPT_POSTFIELDS,$postvars); curl_setopt($ch,CURLOPT_RETURNTRANSFER, true); curl_setopt($ch,CURLOPT_CONNECTTIMEOUT ,3); curl_setopt($ch,CURLOPT_TIMEOUT, 20); $response = curl_exec($ch); print "curl response is:" . $response; curl_close ($ch);
?>
Source : https://stackoverflow.com/questions/2138527/php-curl-and-http-post-example | Last Update : Mon, 26 Jun 23