php curl simulates the post submission data example

  • 2020-12-07 03:59:49
  • OfStack


<?
header("Content-type: text/html; charset=utf8");
/*
 *  Submit a request 
* @param $header array  Need to configure the domain name and so on header Set up the  array("Host: devzc.com");
* @param $data string  The data that needs to be submitted  'user=xxx&qq=xxx&id=xxx&post=xxx'....
* @param $url string  To submit url 'http://192.168.1.12/xxx/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<br>"; 
$ret = curl_post($header, $data,$url);
$utf8 = iconv('GB2312', 'UTF-8//IGNORE', $ret);
echo 'return:<br>'.nl2br($utf8 ).'<br>';
?>


Related articles: