An easy way to parse curl submit Get,post,cookie

Source: Internet
Author: User
Tags curl
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;

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.