-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev-simplecurl.inc
More file actions
38 lines (33 loc) · 1.08 KB
/
Copy pathdev-simplecurl.inc
File metadata and controls
38 lines (33 loc) · 1.08 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
<?PHP
function do_curl($url, $uri, &$soap_error, $postfields, $timeout=15) {
if ($postfields) {
$de = http_build_query($postfields);
$post=TRUE;
} else $post=FALSE;
if ($uri) $uri=http_build_query($uri);
$defaults = array(
CURLOPT_URL => $url.$uri,
CURLOPT_TIMEOUT => $timeout,
CURLOPT_POST => $post,
CURLOPT_FORBID_REUSE => 0,
CURLOPT_FOLLOWLOCATION => TRUE,
CURLOPT_RETURNTRANSFER => TRUE,
);
if ($post) $defaults[CURLOPT_POSTFIELDS] = $de;
$ch = curl_init();
curl_setopt_array($ch, $defaults);
$ret = curl_exec($ch);
$soap_error = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return($ret);
}
function do_curl_checked($url, $uri, &$soap_error, &$soap_errdesc, $postfields, $logparam=L_DIE, $timeout=15) {
$ret=do_curl($url, $uri, $soap_error, $postfields, $timeout);
if ($soap_error<200 || $soap_error>=300) {
$soap_errdesc=$ret;
tolog("do_curl failed: HTTP $soap_error/$ret", L_WARN | $logparam);
return(NULL);
}
$soap_errdesc='OK';
return($ret);
}