Я тестировал его на торте 2.0.5, и HttpSocket :: put может отправлять массивы значений ключей или необработанные строки в виде постданных.
Итак, вы можете отправить строку xml напрямую, и удаленный сервер прочитает ее в Raw Post Data i. е. file_get_contents("php://input")
Это работает:
$http = new HttpSocket();
$xml_data = Xml::fromArray($data);
$xml_string = $xml_data->asXML();
$response = $http->put('http://example.com', $xml_string);
Чтобы продемонстрировать это, я создал контроллер с именем RequestXmlTestController, поданный в 'Controllers/RequestXmlTestController.php'
(код ниже), и пустой вид, поданный в 'RequestXmlTests/index.ctp'
Код контроллера:
<?php
App::uses('AppController', 'Controller');
/**
* RequestXmlTest Controller
*
*/
class RequestXmlTestController extends AppController {
/**
* Use no Model
*/
public $uses = array();
/**
* index action
*/
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);
}
/**
* test action
* Test the requests and dump Raw Post Data and Cake's Request object
*/
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');
}
}
Ссылка:
HttpSocket Documentation