PHP code example of itabrezshaikh / unirest-php
1. Go to this page and download the library: Download itabrezshaikh/unirest-php library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
itabrezshaikh / unirest-php example snippets
$headers = array("Accept" => "application/json");
$body = array("foo" => "hellow", "bar" => "world");
$response = Unirest\Unirest::post("http://mockbin.com/request", $headers, $body);
$response->code; // HTTP Status code
$response->headers; // Headers
$response->body; // Parsed body
$response->raw_body; // Unparsed body
$headers = array("Accept" => "application/json");
$body = array("file" => Unirest\File::add("/tmp/file.txt"));
$response = Unirest\Unirest::post("http://mockbin.com/request", $headers, $body);
$headers = array("Accept" => "application/json");
$body = json_encode(array("foo" => "hellow", "bar" => "world"));
$response = Unirest\Unirest::post("http://mockbin.com/request", $headers, $body);
// Mashape auth
Unirest\Unirest::setMashapeKey('<mashape_key>');
// basic auth
Unirest\Unirest::auth('username', 'password');
// custom auth method
Unirest\Unirest::proxyAuth('username', 'password', CURLAUTH_DIGEST);
$response = Unirest\Unirest::get("http://mockbin.com/request", null, null, "username", "password");
Unirest\Unirest::get($url, $headers = array(), $parameters = null)
Unirest\Unirest::post($url, $headers = array(), $body = null)
Unirest\Unirest::put($url, $headers = array(), $body = null)
Unirest\Unirest::patch($url, $headers = array(), $body = null)
Unirest\Unirest::delete($url, $headers = array(), $body = null)
$request = Unirest\Unirest::prepare(Unirest\Method::LINK, $url, $headers = array(), $body);
$request = Unirest\Unirest::prepare('CHECKOUT', $url, $headers = array(), $body);
//and then
$response = $request->getResponse();
Unirest\Unirest::jsonOpts(true, 512, JSON_NUMERIC_CHECK & JSON_FORCE_OBJECT & JSON_UNESCAPED_SLASHES);
Unirest\Unirest::timeout(5); // 5s timeout
// quick setup with default port: 1080
Unirest\Unirest::proxy('10.10.10.1');
// custom port and proxy type
Unirest\Unirest::proxy('10.10.10.1', 8080, CURLPROXY_HTTP);
// enable tunneling
Unirest\Unirest::proxy('10.10.10.1', 8080, CURLPROXY_HTTP, true);
// basic auth
Unirest\Unirest::proxyAuth('username', 'password');
// basic auth
Unirest\Unirest::proxyAuth('username', 'password', CURLAUTH_DIGEST);
Unirest\Unirest::defaultHeader("Header1", "Value1");
Unirest\Unirest::defaultHeader("Header2", "Value2");
Unirest\Unirest::defaultHeaders(array(
"Header1" => "Value1",
"Header2" => "Value2"
));
Unirest\Unirest::clearDefaultHeaders();
Unirest\Unirest::verifyPeer(false); // Disables SSL cert validation
// alias for `curl_getinfo`
Unirest\Unirest::getInfo()
// returns internal cURL handle
Unirest\Unirest::getCurlHandle()
json
{
"pimatic/unirest-php": "2.*"
}
}
shell
composer
shell
composer
shell
git clone [email protected] :apimatic/unirest-php.git