Hi, liebe Entwickler
Kann mir jemand helfen, dieses Script so anzupassen, dass die Daten in einem sauberen XML-Format anstatt im JSON-Format ausgegeben werden?
<?php
$url = 'https://cct.connects.ch/api/v1/index.php/partner/promotions';
$method = 'GET';
$privateHash = 'SXSezQj41tmhUAkOsYEKjPlGI1pPAo7LbzgEToVY3Uaf05GB6Wreh3zzYYPTlfYu';
$headers = array(
'Accept: application/json',
'Content-Type: application/json',
'lea-Public: BdOj1M3maDs6pOIYxecdO0eL2gT7Pbxp4s2OiI3VDLnc6IVsXh8TORDwYa13XWc6'
);
$data = json_encode(
array(
)
);
if( strlen( $data ) <= 2 )
$data = '';
//lea-Hash erstellen, es werden Kleinbuchstaben erwartet
$headers[] = 'lea-Hash: '. hash_hmac('sha256', $data, $privateHash);
$handle = curl_init();
curl_setopt($handle, CURLOPT_URL, $url);
curl_setopt($handle, CURLOPT_HTTPHEADER, $headers);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, false);
switch($method) {
case 'GET':
break;
case 'POST':
curl_setopt($handle, CURLOPT_POST, true);
curl_setopt($handle, CURLOPT_POSTFIELDS, $data);
break;
case 'PUT':
curl_setopt($handle, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($handle, CURLOPT_POSTFIELDS, $data);
break;
case 'DELETE':
curl_setopt($handle, CURLOPT_CUSTOMREQUEST, 'DELETE');
break;
}
$response = curl_exec($handle);
$code = curl_getinfo($handle, CURLINFO_HTTP_CODE);
echo $code . '<br />'; //Status Code der API
echo '<pre>' . print_r( json_decode( $response ), 1 ) . '</pre>';