PHP code example of diginedbv / unirest-php
1. Go to this page and download the library: Download diginedbv/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/ */
diginedbv / unirest-php example snippets
$response = Unirest::post("http://httpbin.org/post", array( "Accept" => "application/json" ),
array(
"parameter" => 23,
"foo" => "bar"
)
);
$response->code; // HTTP Status code
$response->headers; // Headers
$response->body; // Parsed body
$response->raw_body; // Unparsed body
$response = Unirest::post("http://httpbin.org/post", array( "Accept" => "application/json" ),
array(
"file" => Unirest::file("/tmp/file.txt") // Tells Unirest where the file is located
)
);
$response = Unirest::post("http://httpbin.org/post", array( "Accept" => "application/json" ),
json_encode(
array(
"parameter" => "value",
"foo" => "bar"
)
)
);
$response = Unirest::get("http://httpbin.org/get", null, null, "username", "password");
Unirest::get($url, $headers = array(), $parameters = NULL, $username = NULL, $password = NULL)
Unirest::post($url, $headers = array(), $body = NULL, $username = NULL, $password = NULL)
Unirest::put($url, $headers = array(), $body = NULL, $username = NULL, $password = NULL)
Unirest::patch($url, $headers = array(), $body = NULL, $username = NULL, $password = NULL)
Unirest::delete($url, $headers = array(), $body = NULL, $username = NULL, $password = NULL)
Unirest::timeout(5); // 5s timeout
Unirest::defaultHeader("Header1", "Value1");
Unirest::defaultHeader("Header2", "Value2");
Unirest::clearDefaultHeaders();
Unirest::verifyPeer(false); // Disables SSL cert validation
javascript
{
"nirest-php" : "dev-master"
},
"autoload": {
"psr-0": {"Unirest": "lib/"}
}
}
bash