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 ($curl, Curlopt_post, true);
["Content_Type"]=> string) Multipart/form-data; boundary=------077a996f5afe "
To send a file, precede the filename with the @ prefix and use the full path.
When using an array 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 () "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 to achieve better compatibility, smaller request 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