z_post_url_json() added to easily deal with JSON post APIs; without getting content-type unknown warnings/errors. Also added a debug option to z_get|post_url so you could track and log some of these nasty little buggers.
This commit is contained in:
parent
ce36e8a8bb
commit
53d0e855df
@ -125,6 +125,10 @@ function z_fetch_url($url, $binary = false, $redirects = 0, $opts = array()) {
|
|||||||
$ret['body'] = substr($s,strlen($header));
|
$ret['body'] = substr($s,strlen($header));
|
||||||
$ret['header'] = $header;
|
$ret['header'] = $header;
|
||||||
|
|
||||||
|
if(x($opts,'debug')) {
|
||||||
|
$ret['debug'] = $curl_info;
|
||||||
|
}
|
||||||
|
|
||||||
@curl_close($ch);
|
@curl_close($ch);
|
||||||
return($ret);
|
return($ret);
|
||||||
}
|
}
|
||||||
@ -251,11 +255,24 @@ function z_post_url($url,$params, $redirects = 0, $opts = array()) {
|
|||||||
|
|
||||||
$ret['body'] = substr($s,strlen($header));
|
$ret['body'] = substr($s,strlen($header));
|
||||||
$ret['header'] = $header;
|
$ret['header'] = $header;
|
||||||
|
|
||||||
|
if(x($opts,'debug')) {
|
||||||
|
$ret['debug'] = $curl_info;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
curl_close($ch);
|
curl_close($ch);
|
||||||
return($ret);
|
return($ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function z_post_url_json($url,$params,$redirects = 0, $opts = array()) {
|
||||||
|
|
||||||
|
$opts = array_merge($opts,array('headers' => array('Content-Type: application/json')));
|
||||||
|
return z_post_url($url,json_encode($params),$redirects,$opts);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function json_return_and_die($x) {
|
function json_return_and_die($x) {
|
||||||
header("content-type: application/json");
|
header("content-type: application/json");
|
||||||
|
Reference in New Issue
Block a user