PHP code example of cry / cry-cms-curl
1. Go to this page and download the library: Download cry/cry-cms-curl 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/ */
cry / cry-cms-curl example snippets
$response = CURL::code('https://postman-echo.com/status/404', 10)->send();
$response = CURL::get('https://postman-echo.com/get')
->data('test', '123')
->data('array', [1, 2, 3])
->send();
$response = CURL::post('https://postman-echo.com/post')
->data('test', '123')
->send();
$response = CURL::post('https://postman-echo.com/post')
->data('test', '123')
->header('Content-Type', ContentType::APPLICATION_X_WWW_FORM_URLENCODED)
->send();
$tmpFile = tempnam(sys_get_temp_dir(), 'File_') . '.txt';
file_put_contents($tmpFile, 'File content');
$response = CURL::post('https://postman-echo.com/post')
->data([
'field1' => 'V1',
'field2' => 'V2',
])
->file('file', $tmpFile)
->send();
$response = CURL::json('https://postman-echo.com/post')
->data('test', '123')
->send();
$response = CURL::get('https://postman-echo.com/get')
->authorizationBearer('token')
->send();
CURLResponseDTO Object
(
[location] => <query location>
[method] => <used method>
[isSuccess] => <true or false>
[httpCode] => <answer http code>
[httpCodeText] => <text representation of the response code>
[contentType] => <answer content type>
[body] => <response body>
)
$bash = CUrl::post('https://postman-echo.com/post')
->data([
'field1' => 'V1',
'field2' => 'V2',
])
->file('file', $tmpFile)
->bash();
bash
curl 'https://postman-echo.com/post' \
--location \
--request 'POST' \
--header 'Content-Type: multipart/form-data' \
--form 'field1=V1' \
--form 'field2=V2' \
--form 'file=@/tmp/TestFile_YYj8rW.txt;type=text/plain'