Я немного раздражаюсь больше всего на свете. Может потому что я устал?
Моя проблема заключается в следующем коде продолжает выгружать в строку. Я что-то пропустил? Если я не ошибаюсь, это должно быть скручивание в XML в переменной, а затем я смогу разобрать это?
<?php
$vcenter = "https://vcenter-65-ent.domain.com/rest/vcenter/vm/";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $vcenter);
//curl_setopt($curl, CURLOPT_FAILONERROR,1);
//curl_setopt($curl, CURLOPT_FOLLOWLOCATION,1);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('vmware-api-session-id: SOMESESSIONID', 'Accept: application/xml', 'Content-Type: application/xml' ));
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
//curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
//curl_setopt($curl, CURLOPT_HEADER, 0);
$str = curl_exec($curl);
echo $str;
curl_close($curl);
?>
и вот как я вижу, какой это тип вывода. Это JSON:
<?php
$vcenter = "https://vcenter-65-ent.corp.intusurg.com/rest/vcenter/vm/vm-9520";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $vcenter);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('vmware-api-session-id: 6088820e0383d5b42110b208d642859d', 'Accept: application/json', 'Content-Type: application/json' ));
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$str = curl_exec($curl);
curl_close($curl);
$arr = json_decode($str);
echo gettype($arr);
?>
выход:
{"value":{"cdroms":[{"value":{"start_connected":true,"backing":{"iso_file":"[M70-vmware-Linux-1] iso/rhel-server-7.2-x86_64-dvd.iso","type":"ISO_FILE"},"allow_guest_control":true,"label":"CD/DVD drive 1","ide":{"primary":false,"master":true},"state":"CONNECTED","type":"IDE"},"key":"3002"}],"memory":{"hot_add_increment_size_MiB":128,"size_MiB":12288,"hot_add_enabled":true,"hot_add_limit_MiB":196608},"disks":[{"value":{"scsi":{"bus":0,"unit":0},"backing":{"vmdk_file":"[DATASTORE] Server.vmdk","type":"VMDK_FILE"},"label":"Hard disk 1","type":"SCSI","capacity":53687091200},"key":"2000"}],"parallel_ports":[],"sata_adapters":[],"cpu":{"hot_remove_enabled":false,"count":4,"hot_add_enabled":true,"cores_per_socket":2},"scsi_adapters":[{"value":{"scsi":{"bus":0,"unit":7},"pci_slot_number":160,"label":"SCSI controller 0","type":"PVSCSI","sharing":"NONE"},"key":"1000"}],"power_state":"POWERED_ON","floppies":[{"value":{"start_connected":false,"backing":{"type":"CLIENT_DEVICE"},"allow_guest_control":true,"label":"Floppy drive 1","state":"NOT_CONNECTED"},"key":"8000"}],"name":"Server","nics":[{"value":{"start_connected":true,"pci_slot_number":192,"backing":{"network_name":"VM_VLAN240","type":"STANDARD_PORTGROUP","network":"network-666"},"mac_address":"00:00:00:00:00:00","mac_type":"ASSIGNED","allow_guest_control":true,"wake_on_lan_enabled":true,"label":"Network adapter 1","state":"CONNECTED","type":"VMXNET3","upt_compatibility_enabled":false},"key":"4000"}],"boot":{"delay":0,"retry_delay":10000,"enter_setup_mode":false,"type":"BIOS","retry":false},"serial_ports":[],"guest_OS":"RHEL_6_64","boot_devices":[],"hardware":{"upgrade_policy":"NEVER","upgrade_status":"NONE","version":"VMX_08"}}}
Ваши заголовки предлагают XML.
Для строки XML:
$array = simplexml_load_string($strXML);
print_r($array);
Для строки JSON:
$array = json_decode($strJSON, true);
print_r($array);
Других решений пока нет …