-
Notifications
You must be signed in to change notification settings - Fork 45
/
HttpService.php
53 lines (40 loc) · 1.13 KB
/
HttpService.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
<?php
namespace Microsoft\BingAds\Auth;
use Exception;
/**
* A helper class used to construct an URL with parameters and execute
* HTTP operations.
*/
class HttpService
{
public function post($url, $postData) {
$ch = curl_init();
$query = "";
foreach ($postData as $key => $val) {
if(strlen($query) > 0)
{
$query = $query . '&';
}
$query = $query . $key . '=' . rawurlencode($val);
}
$options = array(
CURLOPT_URL => $url,
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_FOLLOWLOCATION => 1,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_POST => TRUE,
CURLOPT_POSTFIELDS => $query);
curl_setopt_array($ch, $options);
$response = curl_exec($ch);
if(FALSE === $response)
{
$curlErr = curl_error($ch);
$curlErrNum = curl_errno($ch);
curl_close($ch);
throw new Exception($curlErr, $curlErrNum);
}
curl_close($ch);
return $response;
}
}