How do you pass $_POST
values to a page using cURL
?
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
Check out the cUrl PHP documentation page. It will help much more than just with example scripts.
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
Ross has the right idea for POSTing the usual parameter/value format to a url.
I recently ran into a situation where I needed to POST some XML as Content-Type "text/xml" without any parameter pairs so here's how you do that:
In my case, I needed to parse some values out of the HTTP response header so you may not necessarily need to set
CURLOPT_RETURNTRANSFER
orCURLOPT_HEADER
.Check out this page which has an example of how to do it.