-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathputUser.php
90 lines (56 loc) · 1.64 KB
/
putUser.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
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
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
/**
* Example API call
* PUT for edit an object
*/
$server1 = '';
$server2 = '';
// Mandatory fields for POST/PUT method
// PUT in this case updates....
$data = array(
"Login" => "36370",
"Name" => "Jean Claude Van Damme XII",
"Group" => "TEST_wl3_g1",
"Enable" => "0"
);
$data_string = json_encode($data);
// initialize array
$url = array();
foreach ($data as $key => $value)
{
// make the url encoded query string
$url[] = 'fields[]='.urlencode($key.'=='.$value);
}
$url = implode('&', $url);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://$server1/MP.MetaTrader.WebApi//api/users");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// specify post method and options
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
$headers = array(
'Content-type: application/json',
//Auth header is formed by user,pass,ip:port of MT4 server
'Authorization: MetaTrader XXXXX',
'Accept: application/json',
'Content-Length: ' . strlen($data_string)
);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
// execute the request
$output = curl_exec($ch);
$response = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$header_len = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$header = substr($output, 0, $header_len);
$body = substr($output, $header_len);
// output the profile information - includes the header
$json = json_decode($body, true);
echo '<pre>';
print_r($header);
echo '</pre>';
echo '<pre>';
print_r($json);
echo '</pre>';
curl_close($ch);