Fixed a check on json validity that was wrongly against “false” instead of “null”; minor changes

This commit is contained in:
pezcurrel 2024-10-31 20:26:21 +01:00
parent c7eacfb643
commit 32bbec81fe

View file

@ -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']))