Rize S. answered 03/23/23
Senior IT Certified Trainer, IT Developer & DBA Administrator
Sure! Here's an example of how to use PHP's curl library to make an HTTP POST request with the data you provided:
<?php
// Set the URL you want to post to
$url = 'http://www.domain.com';
// Set the data you want to send
$data = array(
'username' => 'user1',
'password' => 'passuser1',
'gender' => '1'
);
// Initialize curl
$ch = curl_init();
// Set the curl options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Execute the curl request
$response = curl_exec($ch);
// Close the curl handle
curl_close($ch);
// Display the response
echo $response;
?>
In this example, we first set the URL we want to post to ($url) and the data we want to send ($data). We then initialize curl ($ch) and set the curl options using curl_setopt(). Specifically, we set the URL, set the request method to POST, set the data to be sent using http_build_query(), and set CURLOPT_RETURNTRANSFER to true to make sure curl returns the response instead of outputting it directly.
After setting the options, we execute the curl request using curl_exec() and store the response in $response. Finally, we close the curl handle using curl_close() and display the response using echo.
This should be enough to make an HTTP POST request with the data you provided and get a response back.