Possiedo un'applicazione con un'API RESTful dei servizi Web. Quando faccio richieste HTTP GET nel browser ottengo risposte XML.PHP XML CURL HTTP Formato XML
Quando faccio la stessa richiesta utilizzando PHP ottengo le informazioni corrette ma non è formattato in XML e quindi non posso passarlo a Simple XML.
Ecco il mio codice.
<?php
//Deifne user credentials to use with requests
$user = "user";
$passwd = "user";
//Define header array for cURL requestes
$header = array('Contect-Type:application/xml', 'Accept:application/xml');
//Define base URL
$url = 'http://192.168.0.100:8080/root/restful/';
//Define http request nouns
$ls = $url . "landscapes";
//Initialise cURL object
$ch = curl_init();
//Set cURL options
curl_setopt_array($ch, array(
CURLOPT_HTTPHEADER => $header, //Set http header options
CURLOPT_URL => $ls, //URL sent as part of the request
CURLOPT_HTTPAUTH => CURLAUTH_BASIC, //Set Authentication to BASIC
CURLOPT_USERPWD => $user . ":" . $passwd, //Set username and password options
CURLOPT_HTTPGET => TRUE //Set cURL to GET method
));
//Define variable to hold the returned data from the cURL request
$data = curl_exec($ch);
//Close cURL connection
curl_close($ch);
//Print results
print_r($data);
?>
Qualsiasi pensiero o suggerimento sarebbe davvero utile.
S
EDIT:
Quindi questa è la risposta che ricevo da codice PHP:
0x100000rhel-mlsptrue9.2.3.0101
Questa è la risposta se uso il WizTools Resto cliente o di un browser.
<?xml version="1.0" encoding="UTF-16"?>
<landscape-response total-landscapes="1" xmlns="http://www.url.com/root/restful/schema/response">
<landscape>
<id>0x100000</id>
<name>rhel-mlsp</name>
<isPrimary>true</isPrimary>
<version>9.2.3.010</version>
</landscape>
</landscape-response>
Come si può vedere le informazioni sono lì, ma il PHP non è realmente presentare questa in modo utile.
Hmm non è sicuro di cosa sarebbe dovuto succedere ma utilizzando il codice ho appena ottenuto un'eccezione irreversibile. – Simon
Ho trovato il motivo per cui non visualizza le informazioni correttamente e questo perché i tag nell'XML sono sconosciuti. Penso di aver bisogno di includere un file di schema in modo che sappia cosa fare con tutto questo. – Simon