POST Requests
suggest changeIf you want to mimic an HTML form POST, you can use cURL. An array passed to CURLOPT_POSTFIELDS is sent as multipart/form-data. A normal form without a multipart enctype is application/x-www-form-urlencoded; pass http_build_query($post) for that.
// POST data in array
$post = [
'a' => 'apple',
'b' => 'banana'
];
// Create a new cURL resource with URL to POST
$ch = curl_init('http://www.example.com');
// We set parameter CURLOPT_RETURNTRANSFER to read output
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Let's pass POST data
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
// We execute our request, and get output in a $response variable
$response = curl_exec($ch);
// Close the connection
curl_close($ch);
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents