[英]Cakephp XML HTTP server how to get the request from client
This is my codes: 这是我的代码:
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 );
}
}
How can I get the $xml_string
in server
? 如何在server
获取$xml_string
? Any ideas? 有任何想法吗?
In your $http->get
call, you're passing the $xml_string
as a parameter. 在$http->get
调用中,您将$xml_string
作为参数传递。 You should be able to receive that in your server
function simply by changing the declaration as follows: 您只需通过如下更改声明就可以在server
函数中收到该server
:
public function server($xml_string) {
Note that there may be URL encoding issues to consider here; 请注意,这里可能要考虑URL编码问题。 I've never worked with this sort of setup. 我从来没有使用过这种设置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.