Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cakephp XML HTTP服务器如何从客户端获取请求_Xml_Api_Http_Cakephp - Fatal编程技术网

Cakephp XML HTTP服务器如何从客户端获取请求

Cakephp XML HTTP服务器如何从客户端获取请求,xml,api,http,cakephp,Xml,Api,Http,Cakephp,这是我的密码: public function client() { App::uses('Xml', 'Utility'); $conditions = array('conditions' => array('title' => 'The title')); App::uses('HttpSocket', 'Network/Http'); $http = new HttpSocket(); $xml_data = Xml::fromA

这是我的密码:

public function client() {  
    App::uses('Xml', 'Utility');
    $conditions = array('conditions' => array('title' => 'The title'));

    App::uses('HttpSocket', 'Network/Http');
    $http = new HttpSocket();
    $xml_data = Xml::fromArray( $conditions, array('pretty'=>'true'));
    $xml_string = $xml_data->asXML();
    $response = $http->get('http://localhost/cakephp/xml/server', $xml_string);
    //echo $response->body;
    echo $response->code;

    $this->set('xml', $response->body);
    $this->set('x', $xml_string);
}

public function server() {
    $this->layout=false;
     $this->response->type('application/xml');
    if($this->request->is('get')){
        $conditionXml = Xml::toArray($this->request->input('Xml::build'));
        //debug($conditionXml['conditions']);
         $title = $conditionXml['conditions']['title'];
       $posts = $this->Post->find('all', array('conditions' =>array('Post.title ='=>$title)));

        $posts = Xml::fromArray(array('posts' => array('post' => $posts)), array('pretty'=>'true', 'format'=>'tags'));
        $posts=$posts->asXML();
        $this->set('posts', $posts );
    }
}


如何在
服务器
中获取
$xml\u字符串
?有什么想法吗?

$http->get
调用中,您将
$xml\u字符串作为参数传递。只需按如下方式更改声明,您就可以在
服务器
功能中接收该声明:

public function server($xml_string) {

注意这里可能有URL编码问题;我从未使用过这种设置。

你说的是基于XML的REST服务器,对吗?