Post Data through cURL
Passing $_POST values to a different page can be achieved using cURL. The process involves activating HTTP POST and setting the post fields for cURL to handle.
Implementation:
$data = ['name' => 'Ross', 'php_master' => true]; // File upload support $data['file'] = '@/home/user/world.jpg'; $handle = curl_init($url); curl_setopt($handle, CURLOPT_POST, true); curl_setopt($handle, CURLOPT_POSTFIELDS, $data); curl_exec($handle); curl_close($handle);
Options:
Post Data Encoding:
cURL can encode data in two formats:
curl_setopt($handle, CURLOPT_POSTFIELDS, $data);
curl_setopt($handle, CURLOPT_POSTFIELDS, http_build_query($data));
Additional Resources:
The above is the detailed content of How Can I Use cURL to Submit POST Data?. For more information, please follow other related articles on the PHP Chinese website!