-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.php
More file actions
78 lines (48 loc) · 1.71 KB
/
test.php
File metadata and controls
78 lines (48 loc) · 1.71 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
$env = parse_ini_file('../.env');
/* *** send as json SAVE DATA ************************************************* */
$url = $env["APP_HOST"].':'.$env["APP_PORT"]."/api/v1/store";
// Create a new cURL resource
$ch = curl_init($url);
// Setup request to send json via POST
$data = array(
'PAL' => 'PUV',
'cedh' => '1234565',
'cedp' => '1234567'
);
$payload = json_encode(array("user" => $data));
// Attach encoded JSON string to the POST fields
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
// Set the content type to application/json
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
// Return response instead of outputting
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Execute the POST request
$result = curl_exec($ch);
// Close cURL resource
curl_close($ch);
var_dump($result);
/* *** end send as json ************************************************* */
/* *** send as post SAVE DATA ************************************************* */
$url = $env["APP_HOST"].':'.$env["APP_PORT"]."/api/v1/store";
// Create a new cURL resource
$ch = curl_init($url);
// Setup request to send json via POST
$fields = array(
'PAL' => 'PUV',
'cedh' => '1234565',
'cedp' => '1234567'
);
$payload = http_build_query($data);
// Attach encoded fields string to the POST url
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
// Set the content type to http post
curl_setopt($ch, CURLOPT_POST, true);
// Return response instead of outputting
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Execute the POST request
$result = curl_exec($ch);
// Close cURL resource
curl_close($ch);
var_dump($result);
/* *** end send as post ************************************************* */