<?Php
$curl=Curl_init();Initialize a Curl Object
$url= "Http://cart.jd.com/cart/cart.html?backurl=http://item.jd.com/176166.html&rid=0.9533184533 938766";
$header=Array();
$header[] = ' User-agent:5.0 (iPhone; U CPU iPhone os 4_3 like Mac os X; En-US) ';
$header[] = ' accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 ';
$header[]= ' Accept-encoding:gzip,deflate ';
$header[]= '//Can add header content as needed ';
curl_setopt($curl,Curlopt_url,$url);Set the URL address you need to grab
curl_setopt($curl,Curlopt_header, $header Set Header
Curl_setopt ( $curl ,curlopt_returntransfer,1); Outputs the result back to the string
$str = Curl_exec ( $curl curl, request Web page
curl _close $curl Close URL request
return $str ; Returns or displays the result
?>
How to post data
Suppose we go to post a form to http://www.example.com/sendSMS.php
Submit content One is a phone number, a text message content
<?Php
$phoneNumber= ' 13598785110 ';
$message= ' This was a test message about the CURL to POST URL ';
$curlPost= ' Pnumber= '.$phoneNumber.' &message= '.UrlEncode($message).' &submit=send ';Stitching Request Parameters
$url= ' Http://www.example.com/sendSMS.php ';
$header[] = ‘........‘;
$curl=Curl_init();
curl_setopt($curl,Curlopt_url,$url);
curl_setopt($curl,Curlopt_header,$header);
curl_setopt($curl,Curlopt_returntransfer,1);
Curl_setopt ( $curl curlopt_post,1); Set the request mode to post
Curl_seropt ( $curl ,< Span class= "PLN" >curlopt_postfields, $curlPost Set post data
$data = Curl_exec (curl Curl_close ( $curl
?>