2
I am using the Codeigniter Framework and trying to do a system integration via API using XML.
I have to send a file with XML parameters to a server via post. Basically the server has to receive a string with data=xml content.
I tested with Advanced Rest Client (Chrome extension that simulates a POST upload) and worked perfectly, IE, the server is OK.
when I play in PHP code it fails to send XML and returns error 400 (bad request).
Does anyone have any tips?
Follows code:
<?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);
?>
Do you want to send data, or do you want to consume the server data? It was not clear to me.
– Ivan Ferrer
In fact happens the 2, first he sends a request, then he looks for the result (whether it worked out or not). I was able to solve with the crul
– Raphael Cortes