mirror of
https://github.com/php-curl-class/php-curl-class.git
synced 2026-08-21 03:32:08 +00:00
Fix #459: Add example with json response as associative array
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
require __DIR__ . '/vendor/autoload.php';
|
||||
|
||||
use \Curl\Curl;
|
||||
|
||||
// curl \
|
||||
// -X POST \
|
||||
// -d "{"id":"1","content":"Hello world!","date":"2015-06-30 19:42:21"}" \
|
||||
// "https://httpbin.org/post"
|
||||
|
||||
$data = array(
|
||||
'id' => '1',
|
||||
'content' => 'Hello world!',
|
||||
'date' => date('Y-m-d H:i:s'),
|
||||
);
|
||||
|
||||
$curl = new Curl();
|
||||
$curl->setDefaultJsonDecoder($assoc=true);
|
||||
$curl->setHeader('Content-Type', 'application/json');
|
||||
$curl->post('https://httpbin.org/post', $data);
|
||||
var_dump($curl->response['json']);
|
||||
Reference in New Issue
Block a user