Curl Learning Summary

Source: Internet
Author: User

1. Interface
Function interface ($postfields =array (), $url) {
Set up an array of Post request HTTP header fields
$httpheader =array ("Content-type:application/x-www-form-urlencoded;charset=utf-8");

Initialize Curl
$ch =curl_init ();

/**
* Set Curl Transfer items
**/
Set HTTP header fields
curl_setopt ($ch, Curlopt_httpheader, $httpheader);
outputting header file information as a data stream
curl_setopt ($ch, Curlopt_header, 0);
Set the URL address of the request
curl_setopt ($ch, Curlopt_url, $url);
Set the method of the request, default to get
curl_setopt ($ch, Curlopt_httpget, 1)//get
curl_setopt ($ch, Curlopt_post, 1); Post
Setting up transfer data
curl_setopt ($ch, Curlopt_postfields, $postfields);
Sets the information obtained by curl_exec () to be returned as a file stream, rather than as a direct output
curl_setopt ($ch, Curlopt_returntransfer, true);

Perform a curl operation
$result = curl_exec ($ch);

Turn off the Curl resource and release the system resources
Curl_close ($ch);

Returns the result of the request
return $result;
}

Curl Learning Summary

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.