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