Through1. Default call method of php curl, access url in get Mode
- ....
- $Ch=Curl_init();
- Curl_setopt ($ ch, CURLOPT_HTTPHEADER, $ header); // sets the http header
- Curl_setopt ($ ch, CURLOPT_ENCODING, "gzip ");
// Set the client to support gzip Compression
- Curl_setopt ($ ch, CURLOPT_CONNECTTIMEOUT, 30 );
// Set the connection wait time
- Curl_setopt ($ ch, CURLOPT_URL, $ url );
- Curl_exec ($ ch );
- If ($Error=Curl_error($ Ch )){
- // Handle errors
- Return-1;
- }
- Fclose ($ fp );
- $Curl_code=Curl_getinfo($ Ch, CURLINFO_HTTP_CODE );
// Obtain the http Return Value
- If ($Curl_code= 200 ){
- // Normal access url
- }
- // Exception
- ....
2. Set http header to support php curl access to the lighttpd Server
- $header[]= 'Expect:';
3. Set curl to get only the http header and not the body:
- curl_setopt($ch, CURLOPT_HEADER, 1);
- curl_setopt($ch, CURLOPT_NOBODY, 1);
Or you can only get the body:
- curl_setopt($ch, CURLOPT_HEADER, 0);
// make sure we get the body
- curl_setopt($ch, CURLOPT_NOBODY, 0);
4. To access the VM, you must set the Host
- $header[]= 'Host: '.$host;
5. Use post, put, delete and other REStful access URLs
- Post:
-
- Curl_setopt ($ ch, CURLOPT_POST, 1 );
-
- Put, delete:
-
- Curl_setopt ($ ch, CURLOPT_CUSTOMREQUEST, "DELETE ");
// Or PUT, which must be supported by the server.
6. php curl saves the downloaded content as a file
- curl_setopt($ch, CURLOPT_FILE, $fp);