A simple way to parse curl to submit Get,post,cookie _php Tutorial

Source: Internet
Author: User
Copy CodeThe 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 ("Multipart/form-data"); boundary=------077a996f5afe "
To send a file, precede the file name with the @ prefix and use the full path.
When using an array to provide post data, the Curl component is presumably intended to be compatible with the @filename of this upload file, by default Content_Type is set to Multipart/form-data.
While there is no impact on most Web servers, there are still a few servers that are incompatible.
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));
In the absence of the need to upload files, as far as possible to the post submitted data http_build_query, and then sent 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

http://www.bkjia.com/PHPjc/327924.html www.bkjia.com true http://www.bkjia.com/PHPjc/327924.html techarticle Copy the code as follows: PHP $get _data = Array ("Get1" = "Get1", "get2" = "Get2", "get3" = "Get3"); $curl = Curl_init (); Curl_seto PT ($curl, Curlopt_url, ' http://test.test.com/t ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.