Download the PHP package rakit/curl without Composer
On this page you can find all versions of the php package rakit/curl. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package curl
rakit-curl
Just another PHP cURL wrapper
Installation
As you can see, this library contain composer.json
file. But at this time, i have not post this library on packagist. So if you want to use it via composer, you can manually add this repository in your composer.json
file.
So, your composer.json
file should look like this:
Then you can run composer install
or composer update
.
Optionally you can download/clone this library and load it into your project.
Examples
Example Get Request
Using Request Parameter
or
Example Post Request
Upload file? use addFile method
Send a cookie
Auto Redirect
Auto redirect allow cURL to auto redirect while response is redirection (status: 3xx).
Example:
Storing Session
It is easy way to store session automatically with CURLOPT_COOKIEJAR and CURLOPT_COOKIEFILE. It is useful when you want to grab something that require session cookies to login or anything else. For use this, you must have directory that have access to write file for storing session.
For example you want grab redirected page after login:
Create Simple Request
With simple request, you dont't need to create new Curl request object. But you can't send a cookie, modify request headers, or even curl options.
Response Object
In examples above, i always told you to do something with response object, but what it is? what you can do with response object?
Response object is object that returned from your cURL request. Response object contain result data from HTTP response such as response headers, cookies, body, etc.
Here is that you can do with response object:
isNotFound()
Shortcut for check response status code is 404 or not.
isRedirect()
Return true if status code is 3xx.
getBody()
Getting response body like html code, image content, etc.
length()
Getting response length (response body string + response header string).
isHtml()
Return true if response content-type is text/html.
error()
Return true if there is error in request
getErrno()
Getting error code, 0 = no error.
getErrorMessage()
Getting error message, empty if no error
getHeader($key, $default = null)
Getting header item
getHeaders()
Getting all header items as array.
getHeaderString()
Get response headers as raw header string.
getStatusCode()
Getting response status code.
getContentType()
Shortcut for getting response content-type.
getInfo($key, $default = null)
Getting info item like curl_getinfo()
getAllInfo()
Getting all info as array.