forked from 4iz278/cviceni
-
Notifications
You must be signed in to change notification settings - Fork 0
/
12-php-client-put.php
44 lines (36 loc) · 1.47 KB
/
12-php-client-put.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
$url='https://jirihradil.com/api/clients/1.json';
$data_json='{"first_name":"JimmyX","last_name":"Page", "street":"3651 Lindell Rd. Suite D1024","town":"Las Vegas","xname":"xhraj18","zip":"89103"}';
//ukázka odeslání dat metodou PUT prostřednictvím CURL
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Content-Length: ' . strlen($data_json),'Accept: application/json'));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_POSTFIELDS,$data_json);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch,CURLOPT_CONNECTTIMEOUT,120);
curl_setopt ($ch,CURLOPT_TIMEOUT,120);
curl_setopt ($ch,CURLOPT_MAXREDIRS,10);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
/* alternativní volání pomocí file_get_content s doplněným contextem
$context = stream_context_create([
'http' => [
'method' => 'PUT',
'header' => "Content-type: application/json\r\n" .
"Accept: application/json\r\n" .
"Connection: close\r\n" .
"Content-length: " . strlen($data_json) . "\r\n",
'protocol_version' => 1.1,
'content' => $data_json
],
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false
]
]);
file_get_contents($url, false, $context);
*/