-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathClient.php
67 lines (58 loc) · 1.32 KB
/
Client.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
<?php
declare(strict_types=1);
namespace Comet;
/**
* Class Client
* Absolutely Expreimental! Please do not use it in production
* @package Comet
*/
class Client {
/**
* Client constructor
*/
public function __construct()
{
}
/**
* @param $url
* @param null $data
* @return false|string
*/
static public function get($url, $data = null)
{
if ($data) {
$url .= '?' . http_build_query($data);
}
return file_get_contents($url);
}
/**
* @param $url
* @param $data
* @return false|string
*/
static public function post($url, $data)
{
if (is_array($data)) {
$data = json_encode($data);
}
$opts = [
'http' => [
'method' => "POST",
'header' =>
"Content-type: application/json\r\n" .
"Accept: application/json\r\n" .
"Connection: close\r\n" .
"Content-length: " . strlen($data) . "\r\n",
'content'=> $data,
'protocol_version' => '1.1',
],
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
]
];
$ctx = stream_context_create($opts);
$result = file_get_contents($url, false, $ctx);
return $result;
}
}