How do you pass $_POST
values to a page using cURL
?
Php – Passing $_POST values with cURL
curlPHPpost
Related Topic
- How to set the authorization header using cURL
- How to display request headers with command line curl
- Php – Reference — What does this symbol mean in PHP
- Json – How to POST JSON data with cURL
- Windows – How to install and use cURL on Windows
- Getting only response header from HTTP POST using cURL
- Using cURL to upload POST data with files
- How are parameters sent in an HTTP POST request
Best Answer
Should work fine.
We have two options here,
CURLOPT_POST
which turns HTTP POST on, andCURLOPT_POSTFIELDS
which contains an array of our post data to submit. This can be used to submit data toPOST
<form>
s.It is important to note that
curl_setopt($handle, CURLOPT_POSTFIELDS, $data);
takes the $data in two formats, and that this determines how the post data will be encoded.$data
as anarray()
: The data will be sent asmultipart/form-data
which is not always accepted by the server.$data
as url encoded string: The data will be sent asapplication/x-www-form-urlencoded
, which is the default encoding for submitted html form data.I hope this will help others save their time.
See:
curl_init
curl_setopt