Copy code The code is as follows:
$get_data = array (
"get1"=> "get1",
"get2" => "get2",
"get3" => "get3"
);
$curl = curl_init();
curl_setopt($ curl, CURLOPT_URL, 'http://test.test.com/test.php?'.http_build_query($get_data));
curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit /537.11 (KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11');
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt( $curl, CURLOPT_FOLLOWLOCATION, true);
$post_data = array (
"p1" => "test1",
"p2" => "test2",
"p3" => ; "test3"
);
curl_setopt($curl, CURLOPT_POST, true);
//["CONTENT_TYPE"]=> string(70) "multipart/form-data; boundary=-- ----077a996f5afe"
//To send a file, prefix the file name with @ and use the full path.
//When using an array to provide post data, the CURL component is probably to be compatible with the @filename writing method for uploading files. By default, the content_type is set to multipart/form-data.
//Although it has no impact on most web servers, there are still a small number of servers that are incompatible.
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);
//["CONTENT_TYPE"]=> string(33) "application/x-www-form-urlencoded"
//curl_setopt($ curl, CURLOPT_POSTFIELDS, http_build_query($post_data));
//When there is no need to upload files, try to http_build_query the data submitted by post, and then send it out, which can achieve better compatibility and smaller requests packet.
$cookies = array(
'c1'=>'v1',
'c2'=>'v2',
'c3'=>'v3',
);
$cookies_string = '';
foreach($cookies as $name=>$value){
$cookies_string .= $name.'='.$value.';';
}
curl_setopt($curl, CURLOPT_COOKIE, $cookies_string);
$result = curl_exec($curl);
curl_close($curl);
var_dump($result);
exit;
http://www.bkjia.com/PHPjc/327924.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/327924.htmlTechArticleCopy the code as follows: ?php $get_data = array ( "get1" = "get1", "get2" = "get2", "get3" = "get3" ); $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, 'http://test.test.com/t...