We pass on1. Default calling method for PHP curl, get access URL
- ....
- $ CH = Curl_init ();
- curl_setopt ($ch, Curlopt_httpheader, $header);//Set HTTP header
- curl_setopt ($ch, curlopt_encoding, "gzip");
Set to support gzip compression for clients
- curl_setopt ($ch, Curlopt_connecttimeout, 30);
Setting the connection Wait time
- curl_setopt ($ch, Curlopt_url, $url);
- Curl_exec ($ch);
- if ($error = curl_error($ch)) {
- Error handling
- return-1;
- }
- Fclose ($FP);
-
- $ Curl_code = Curl_getinfo ($ch, Curlinfo_http_code);
Get the HTTP return value
- if ($curl_code = =) {
- Normal Access URL
- }
- Abnormal
- ....
2. Set HTTP header to support PHP Curl Access LIGHTTPD Server
- $header []= ' Expect: ';
3. Set curl to get the HTTP header only, without getting the body:
- curl_setopt ($ch, Curlopt_header, 1);
- curl_setopt ($ch, curlopt_nobody, 1);
Or just get body:
- curl_setopt ($ch, Curlopt_header, 0);
Make sure we get the body
- curl_setopt ($ch, curlopt_nobody, 0);
4. To access the virtual host, you need to set the host
- $header []= ' Host: '. $host;
5. Use a restful way to access the URL using post, put, delete, etc.
- Post
- curl_setopt ($ch, Curlopt_post, 1);
- Put, delete:
- curl_setopt ($ch, Curlopt_customrequest, "DELETE");
Or put, you need the server to support these methods.
6. PHP Curl saves the downloaded content as a file
- curl_setopt ($ch, Curlopt_file, $fp);
http://www.bkjia.com/PHPjc/446438.html www.bkjia.com true http://www.bkjia.com/PHPjc/446438.html techarticle we pass the default call method to 1. PHP curl, get way access URL .... $ ch = curl_init (); curl_setopt ($ch, Curlopt_httpheader, $header);//Set HTTP header C Url_setopt ($ch, Curlopt_ ...