-
- /**
- * CURL simulates Post submission in PHP
- * by bbs.it-home.org
- */
- $url = 'http://website/a.php';
- $fields = array(
- 'UserName'=>urlencode(' a'),
- 'PWD'=>urlencode('b') ,
- 'AppReturn'=>urlencode('c') ,
- 'AppSQL'=>urlencode('d') ,
- );
- $fields_string = http_build_query($fields);
- $ch = curl_init() ;
- curl_setopt($ch, CURLOPT_URL,$url) ; //Set the URL to be collected
- curl_setopt($ch, CURLOPT_POST,1) ; //Set The form is POST
- curl_setopt($ch, CURLOPT_POSTFIELDS,$fields_string); //Set the Post parameters
- curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); //Print it with a string.
- $re = curl_exec($ch);//(If CURLOPT_RETURNTRANSFER is not set to 1, then the HTML document content will be executed and obtained, such as: 1; otherwise the result will be returned instead of executed)
- print_r($re );
- $info = curl_getinfo($ch);//Requested information
- print_r($info);
- $data = array ('UserName' => 'bar');
- $data = http_build_query($data );
- $opts = array (
- 'http' => array (
- 'method' => 'POST',
- 'header'=> "Content-type: application/x-www-form-urlencodedrn" .
- "Content-Length: " . strlen($data) . "rn",
- 'content' => $data
- ),
- );
- $context = stream_context_create($opts);
- $html = file_get_contents( $url, false, $context);
- echo $html;
- var_dump($http_response_header);
-
Copy code
>>> Further reading:
php code to implement simulated get and post requests
Examples of POST data using socket, curl, file_get_contents methods
The length limit of $_GET $_POST parameters in php
Post and get application example code in php curl
Simple example of php curl post
Example code for php curl to implement get, post and cookie
How to use php to receive parameters and obtain post original data
A simple example of php curl submitting GET, POST and Cookie
Usage of $_GET, $_POST, $_REQUEST and $_SERVER in php
How to batch process POST values in php
Solution to the problem of automatically adding escape characters when passing parameters in PHP form POST
php implements post php curl function to simulate post transmission data
Example of php curl simulating post request
php fsockopen simulates POST submitted code
|