Cakephp XML HTTP服务器如何从客户端获取请求 [英] Cakephp XML HTTP server how to get the request from client
本文介绍了Cakephp XML HTTP服务器如何从客户端获取请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码:
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_string
?有什么想法吗?
How can I get the $xml_string
in server
? Any ideas?
推荐答案
在你的 $ http->获取
电话,您将 $ xml_string
作为参数传递。您应该能够在服务器
函数中接收该函数,只需更改声明如下:
In your $http->get
call, you're passing the $xml_string
as a parameter. You should be able to receive that in your server
function simply by changing the declaration as follows:
public function server($xml_string) {
请注意,可能存在URL编码这里要考虑的问题;我从来没有使用过这种设置。
Note that there may be URL encoding issues to consider here; I've never worked with this sort of setup.
这篇关于Cakephp XML HTTP服务器如何从客户端获取请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文