Parse curl and submit GET, POST, and Cookie. Copy the code as follows :? Php $ get_dataarray (get1get1, get2get2, get3get3); $ curlcurl_init (); curl_setopt ($ curl, CURLOPT_URL, test. test. comt
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.20.1.97 Safari/100 ');
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"
// Add the @ prefix to the file name and use the complete path.
// When the array is used to provide post data, the CURL component is probably used to ensure compatibility with the @ filename method. by default, content_type is set to multipart/form-data.
// Although it does not affect most web servers, a small number of servers are not compatible.
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 ));
// If you do not need to upload files, perform http_build_query on the data submitted by post as much as possible, and then send it out to achieve better compatibility and smaller request data packets.
$ 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;
The http://www.bkjia.com/PHPjc/327924.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/327924.htmlTechArticle code is 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...