13.5.1. ProblemYou want to retrieve a URL using a method more exotic than get or post, such as put or delete. 13.5.2. SolutionJust as when using post, set the method and content stream context options when using the http stream, as in Example 13-24. Using put with the http stream
With cURL, set the CURLOPT_CUSTOMREQUEST option to the method name. To include a request body, set CURLOPT_POSTFIELDS to the the body, as in Example 13-25. Using put with cURL
Example 13-26 shows how to put with HTTP_Request: pass HTTP_REQUEST_METHOD_PUT to the constructor and call setBody( ) with the contents of the request body. Using put with HTTP_Request
13.5.3. DiscussionAs REST-style web services APIs grow more common, so do HTTP requests using lesser lights of the request-method pantheon, such as put and delete. The put method is often used for uploading the contents of a particular file. cURL has three special options to help with this: CURLOPT_PUT, CURLOPT_INFILE, and CURLOPT_INFILESIZE. To upload a file with put and cURL, set CURLOPT_PUT to true, CURLOPT_INFILE a filehandle opened to the file that should be uploaded, and CURLOPT_INFILESIZE to the size of that file. Example 13-27 uploads a file with put. Uploading a file with cURL and put
13.5.4. See AlsoDocumentation on curl_setopt( ) at http://www.php.net/curl-setopt and on stream options at http://www.php.net/wrappers.http; the PEAR HTTP_Request class at http://pear.php.net/package/HTTP_Request; Section 5.1.1 of RFC 2616, which discusses request methods, is available at http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html#sec5.1.1 . |