I tested it on cake 2.0.5, and HttpSocket :: put can send arrays of key values ββor raw strings like postdata.
So you can directly send the xml string and the remote server will read it in Raw Post Data i. e. file_get_contents("php://input")
It works:
$http = new HttpSocket(); $xml_data = Xml::fromArray($data); $xml_string = $xml_data->asXML(); $response = $http->put('http://example.com', $xml_string);
To demonstrate this, I created a controller called RequestXmlTestController registered under 'Controllers/RequestXmlTestController.php' (code below) and an empty view presented under 'RequestXmlTests/index.ctp'
Controller Code:
<?php App::uses('AppController', 'Controller'); class RequestXmlTestController extends AppController { public $uses = array(); public function index(){ App::uses('HttpSocket', 'Network/Http'); App::uses('Xml', 'Utility'); $http = new HttpSocket(); $data = array( 'type' => array('name' => 'Campaign', 'data' => array( array('name' => 'Come eat at Joe\'s', 'products' => array('adserver', 'analytics')) )) ); $xml_data = Xml::fromArray($data); $xml_string = $xml_data->asXML(); $response = $http->put(Router::url(array('action' => 'test'), true), $xml_string); debug($response); } public function test(){ var_dump(array('raw_post_data' => file_get_contents("php://input"))); echo "\n\n"; var_dump($this->request); exit; $this->render('index'); } }
References: HttpSocket Documentation
source share