When I make a HTTP GET request, with curl, via php, I get this response:
<?xml version="1.0" encoding="ISO-8859-1"?>
<root>
<apiStatus>ok</apiStatus>
<matches>1</matches>
<unit type="campaign">
<id>42</id>
<name>think_deep</name>
</unit>
<units>1</units>
</root>
When I try to get this output, to create a SimpleXMLElement, I get this erropr:
PHP Warning: SimpleXMLElement::__construct(): Entity: line 1: parser error : Start tag expected, '<' not found in /home/simone/Development/dotadv/cxense/scripts/SearchForCampaign.php on line 35
PHP Warning: SimpleXMLElement::__construct(): 1 in /home/simone/Development/dotadv/cxense/scripts/SearchForCampaign.php on line 35
PHP Warning: SimpleXMLElement::__construct(): ^ in /home/simone/Development/dotadv/cxense/scripts/SearchForCampaign.php on line 35
PHP Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /home/simone/Development/dotadv/cxense/scripts/SearchForCampaign.php:35
Stack trace:
#0 /home/simone/Development/dotadv/cxense/scripts/SearchForCampaign.php(35): SimpleXMLElement->__construct('1')
#1 {main} thrown in /home/simone/Development/dotadv/cxense/scripts/SearchForCampaign.php on line 35
With a var_dump() I discovered that the output is:
<?xml version="1.0" encoding="ISO-8859-1"?>
<root>
<apiStatus>ok</apiStatus>
<matches>1</matches>
<unit type="campaign">
<id>42</id>
<name>think_deep</name>
</unit>
<units>1</units>
</root>
bool(true)
bool(true)
So, ... What kind of issue is this?
$curl = curl_init();
$url = 'http://stage.emediate.eu' . $request->uri();
curl_setopt_array($curl, [
CURLOPT_URL => $url,
]);
$resp = curl_exec($curl);
var_dump($resp, true);