Skip to content

Commit a4cf524

Browse files
committed
Fix php-curl-class#459: Add example with json response as associative array
1 parent 79e57a7 commit a4cf524

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
require __DIR__ . '/vendor/autoload.php';
3+
4+
use \Curl\Curl;
5+
6+
// curl \
7+
// -X POST \
8+
// -d "{"id":"1","content":"Hello world!","date":"2015-06-30 19:42:21"}" \
9+
// "https://httpbin.org/post"
10+
11+
$data = array(
12+
'id' => '1',
13+
'content' => 'Hello world!',
14+
'date' => date('Y-m-d H:i:s'),
15+
);
16+
17+
$curl = new Curl();
18+
$curl->setDefaultJsonDecoder($assoc=true);
19+
$curl->setHeader('Content-Type', 'application/json');
20+
$curl->post('https://httpbin.org/post', $data);
21+
var_dump($curl->response['json']);

0 commit comments

Comments
 (0)