I am using the Framework Codeigniter and trying to do a system integration via API using XML.
I have to make a file upload with XML parameters to a server via post. Basically the server has to receive a string with date = xml content.
I tested with the Advanced Rest Client (chrome extension that simulates a POST sending) and it worked perfectly, ie the server is OK.
When playing in PHP code it can not send XML and returns error 400 (bad request).
Does anyone have any tips?
Follow the code below:
<?php
$query = $this -> db -> query('SELECT token FROM configuracao LIMIT 1');
$row = $query -> row_array();
$token = $row['token'];
$conteudoXML= "data=";
$conteudoXML.= "<schedule>";
$conteudoXML.= "<alternativeIdentifier>1234567</alternativeIdentifier>";
$conteudoXML.= "<observation>1234567</observation>";
$conteudoXML.= "<agent><id>220876</id></agent>";
$conteudoXML.= "<serviceLocal><alternativeIdentifier>teste</alternativeIdentifier></serviceLocal>";
$conteudoXML.= "<activitiesOrigin>4</activitiesOrigin>";
$conteudoXML.= "<date>2015-11-25</date>";
$conteudoXML.= "<hour>00:00</hour>";
$conteudoXML.= "<activityRelationship>";
$conteudoXML.= "<activity><alternativeIdentifier>corretiva</alternativeIdentifier></activity>";
$conteudoXML.= "</activityRelationship>";
$conteudoXML.= "</schedule>";
$url = "http://api.umov.me/CenterWeb/api/$token/schedule.xml";
$xml_str = $conteudoXML;
$post_data = array('xml' => $xml_str);
$stream_options = array(
'http' => array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded' . "\r\n",
'content' => http_build_query($post_data)));
$context = stream_context_create($stream_options);
$response = file_get_contents($url, null, $context);
?>