[php 8] Web service rest php : rien en sortie
Bonjour,
J'ai ceci dans le code :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| function appelWebServiceRest($paramUrl, $paramLogin, $paramPassword) {
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $paramUrl);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); //YD
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); //YD
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD, $paramLogin . ':' . $paramPassword);
curl_setopt($curl, CURLOPT_TIMEOUT, 3600);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); //YD
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Accept: application/json'
));
$reponseEnJson = curl_exec($curl);
//$error = curl_error($curl);
//echo "Curl error: " . $error;
curl_close($curl);
return $reponseEnJson;
} |
Code:
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
| $monJson = $monUtilitaire->appelWebServiceRest('https://vmw-cyberwatch.toto/api/v3/assets/servers?hostname=' . $pNomOrd, 'hbik=', '8owA==');
var_dump($monJson);
$monObjet = json_decode($monJson, true);
var_dump($monObjet);
if (is_array($monObjet)) {
$count = count($monObjet);
} else {
$count = 0;
}
if (!empty($monObjet)) {
if ($count > 1) {
$item = $monObjet[0];
if (isset($item['description'])) {
$description = $item['description'];
echo "Description du PC --------------------------------->".$description;
} else {
echo "La clé 'description' n'existe pas dans le tableau.";
}
} else {
echo "Le tableau ne contient pas assez d'éléments.";
}
} else {
echo "Le tableau est vide.";
} |
et le json : via l'url avec le navigateur
Code:
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
| [
{
"id": 10,
"hostname": "l107512",
"description": "Dattt",
"last_communication": "2023-04-04T15:59:58.328+02:00",
"reboot_required": false,
"boot_at": "2023-04-03T13:59:09.000+02:00",
"category": "desktop",
"created_at": "2022-01-25T19:41:52.000+01:00",
"environment": {
"id": 2,
"name": "Medium",
"confidentiality_requirement": "confidentiality_requirement_medium",
"integrity_requirement": "integrity_requirement_medium",
"availability_requirement": "availability_requirement_medium",
"ceiling_cvss_v3": null
},
"os": {
"key": "windows_10_22h2_64",
"name": "Windows 10 22H2",
"arch": "AMD64",
"eol": "2025-05-14T00:00:00.000+02:00",
"short_name": "Windows 10 22H2",
"type": "Os::Windows"
},
"groups": [
{
"id": 4,
"name": "DI",
"description": "",
"color": "#12afcb"
}
]
}
] |
J'ai "Le tableau ne contient pas assez d'éléments".
et la var_dump donne : InfoInscription.class.php:30:int 1
Je ne comprends plus rien
Merci