- /**
- * Simulate Post submission using CURL in PHP
- * By bbs.it-home.org
- */
- $ Url = 'http: // website/a. php ';
- $ Fields = array (
- 'Username' => urlencode ('A '),
- 'Pwd' => urlencode ('B '),
- 'Apprecall' => urlencode ('C '),
- 'Appsql' => urlencode ('D '),
- );
- $ Fields_string = http_build_query ($ fields );
- $ Ch = curl_init ();
- Curl_setopt ($ ch, CURLOPT_URL, $ url); // you can specify the URL to be collected.
- Curl_setopt ($ ch, CURLOPT_POST, 1); // The format is POST.
- Curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ fields_string); // you can specify the Post parameter.
- Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1); // Print it out with a string.
- $ Re = curl_exec ($ ch); // (if CURLOPT_RETURNTRANSFER is not set to 1, the HTML document content will be executed and retrieved, for example, 1; otherwise, the result will be returned, instead of executing)
- Print_r ($ re );
- $ Info = curl_getinfo ($ ch); // request 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-urlencoded \ r \ n ".
- "Content-Length:". strlen ($ data). "\ r \ n ",
- 'Content' => $ data
- ),
- );
- $ Context = stream_context_create ($ opts );
- $ Html = file_get_contents ($ url, false, $ context );
- Echo $ html;
- Var_dump ($ http_response_header );
>>> Additional reading: php code for simulating get and post requests php uses the socket, curl, file_get_contents method to POST data instance php $ _ GET $ _ POST parameter length limit php curl post and get simple example of php curl post using the application instance code php curl to implement get, post and cookie instance code php receiving parameters and methods for obtaining post original data php curl submit GET, POST, Cookie simple instance php $ _ GET, $ _ POST, $ _ REQUEST and $ _ SERVER usage php method for batch processing POST values PHP form POST parameters automatically add escape character problem solution php implementation post php curl simulate post data transmission example of using php curl to simulate a post request php fsockopen to simulate the code submitted by POST |