diff --git a/lib/httpjson.php b/lib/httpjson.php index 170f1bd..e803c79 100644 --- a/lib/httpjson.php +++ b/lib/httpjson.php @@ -9,14 +9,14 @@ function httpjson($endpoint,$timeout=null,$method=null,$postdata=null,$accept=nu 'http'=>[ 'timeout'=>$timeout, 'method'=>$method, - 'user_agent'=>'Mozilla/5.0 (X11; Linux x86_64; rv:121.0) Gecko/20100101 Firefox/121.0', + 'user_agent'=>'httpjson/1.1', 'header'=>"Accept: {$accept}\r\n", 'ignore_errors'=>true ] ]; if (!is_null($token)) $context['http']['header'].="Authorization: Bearer {$token}\r\n"; if (!is_null($postdata)) { - $context['http']['header'].="Content-type: application/x-www-form-urlencoded\r\n"; + $context['http']['header'].="Content-type: application/x-www-form-urlencoded\r\nIdempotency-Key: ".md5(implode('-',$postdata).time())."\r\n"; $context['http']['content']=http_build_query($postdata); } $context=stream_context_create($context); @@ -46,7 +46,7 @@ function httpjson($endpoint,$timeout=null,$method=null,$postdata=null,$accept=nu $errors[]="«got no headers"; } $res=@json_decode($res,true); - if ($res===false) { + if (is_null($res)) { $errors[]="got no valid JSON"; } else { if (count($errors)>0 && isset($res['error']))