This article is a curl submitted Get,post,cookie simple method for detailed analysis of the introduction, the need for a friend reference
copy code 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/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 ($c URL, curlopt_post, true);
//["Content_Type"]=> string () Multipart/form-data; boundary=------077a996f5afe "
//To send the file, precede the filename with the @ prefix and use the full path.
//When using arrays to provide post data, the Curl component is probably designed to be compatible with @filename this upload file, by default the Content_Type is set to Multipart/form-data.
//Although it does not affect most Web servers, there are a few servers that are not compatible.
curl_setopt ($curl, Curlopt_postfields, $Post_data);
//["Content_Type"]=> string (a) "application/x-www-form-urlencoded"
//curl_setopt ($curl, Curlopt_ Postfields, Http_build_query ($post _data));
//In the absence of the need to upload files, try to http_build_query the data submitted by post, and then send it out, to achieve better compatibility, smaller request packets.
$cookies = Array (
' C1 ' => ' v1 ',
' C2 ' => ' v2 ',
' C3 ' => ' v3 ',
);
$cookies _string = ';
Fore Ach ($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;