This article describes how to simulate post data submission using phpcurl.
The Code is as follows:
Header ("Content-type: text/html; charset = utf8 ");
/*
* Submit a request
* @ Param $ header array set the array ("Host: devzc.com") for the domain name and other headers to be configured ");
* @ Param $ data string the data to be submitted 'user = xxx & qq = xxx & id = xxx & post = XXX '....
* @ Param $ url string the url to be submitted 'HTTP: // 192.168.1.12/xxx/api /';
*/
Function curl_post ($ header, $ data, $ url)
{
$ Ch = curl_init ();
$ Res = curl_setopt ($ ch, CURLOPT_URL, $ url );
Var_dump ($ res );
Curl_setopt ($ ch, CURLOPT_SSL_VERIFYHOST, FALSE );
Curl_setopt ($ ch, CURLOPT_SSL_VERIFYPEER, FALSE );
Curl_setopt ($ ch, CURLOPT_HEADER, 0 );
Curl_setopt ($ ch, CURLOPT_POST, 1 );
Curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ data );
Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1 );
Curl_setopt ($ ch, CURLOPT_HTTPHEADER, $ header );
$ Result = curl_exec ($ ch );
Curl_close ($ ch );
If ($ result = NULL ){
Return 0;
}
Return $ result;
}
$ Url = 'HTTP: // 127.0.0.1 ';
$ Header = array ("Host: 127.0.0.1 ",
"Content-Type: application/x-www-form-urlencoded ",
'Referer: http: // 127.0.0.1/toolindex.xhtml ',
'User-Agent: Mozilla/4.0 (compatible; MSIE. 0; Windows NT 6.1; Trident/4.0; SLCC2 ;)');
$ Data = 'tools _ id = 1 & env = gamma ';
Echo "argv: $ data
";
$ Ret = curl_post ($ header, $ data, $ url );
$ Utf8 = iconv ('gb2312', 'utf-8 // IGNORE ', $ ret );
Echo 'Return:
'. Nl2br ($ utf8 ).'
';
?>