[support] How to send a XML to drupal menu callback
Metzler, David
metzlerd at evergreen.edu
Tue Jun 29 14:37:35 UTC 2010
Ummm... Looks like you're mixing your metaphores.
To pass variables using CGI, they must be properly encoded key value
pairs. Example:
$data = array('xml'=>$xml);
$data_string = drupal_query_string_encode($data);
drupal_http_request("http://mysite.it/foo",$header,"POST",$xml,3);
Alternatively you could use multipart file upload data, but this is how
I most often do it when creating rest XML web services.
-----Original Message-----
From: support-bounces at drupal.org [mailto:support-bounces at drupal.org] On
Behalf Of Michel Morelli
Sent: Monday, June 28, 2010 7:37 AM
To: support at drupal.org
Subject: [support] How to send a XML to drupal menu callback
Hi all. I need to receive via POST an XML.
I have created this hook_menu() entry:
$items['foo'] = array(
'title' => 'Get xml',
'page callback' => 'zb_bar',
'access arguments' => array('access content'),
'type' => MENU_NORMAL_ITEM,
);
and this is my function:
function zb_bar() {
ob_start();
var_dump($_POST);
$mailBody = ob_get_contents();
ob_end_clean();
echo $mailBody;
exit;
}
This is my test_script.php:
include_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
$xml = '<?xml version="1.0"
encoding="ISO-8859-1"?><req>pippo</req>';
//$header = array('Content-Type' =>
'application/x-www-form-urlencoded');
$header = array('Content-Type' => 'text/xml');
$ret =
drupal_http_request("http://mysite.it/foo",$header,"POST",$xml,3);
var_dump($ret);
And this is $ret content:
object(stdClass)#22 (4) {
["request"]=>
string(219) "POST /foo HTTP/1.0
Host: www.mysite.it
User-Agent: Drupal (+http://drupal.org/)
Content-Length: 59
Content-Type: text/html
<?xml version="1.0" encoding="ISO-8859-1"?><req>pippo</req>"
["data"]=>
string(13) "array(0) {
}
"
["headers"]=>
array(11) {
["Date"]=>
string(29) "Mon, 28 Jun 2010 14:40:46 GMT"
["Server"]=>
string(137) "Apache/2.2.9 (Debian) PHP/5.2.13-0.dotdeb.1 with
Suhosin-Patch proxy_html/3.0.0 mod_python/3.3.1 Python/2.5.2
mod_perl/2.0.4 Perl/v5.10.0"
["X-Powered-By"]=>
string(21) "PHP/5.2.13-0.dotdeb.1"
["Set-Cookie"]=>
string(147)
".......................................................................
................................................."
["Expires"]=>
string(29) "Sun, 19 Nov 1978 05:00:00 GMT"
["Last-Modified"]=>
string(29) "Mon, 28 Jun 2010 14:40:46 GMT"
["Cache-Control"]=>
string(25) "post-check=0, pre-check=0"
["Vary"]=>
string(15) "Accept-Encoding"
["Content-Length"]=>
string(2) "13"
["Connection"]=>
string(5) "close"
["Content-Type"]=>
string(24) "text/html; charset=utf-8"
}
["code"]=>
string(3) "200"
}
Why $_POST is empty (see "data" ) ?
M.
--
Michel 'ZioBudda' Morelli michel at ziobuddalabs.it
Sviluppo applicazioni CMS DRUPAL e web dinamiche (LAMP+Ajax)
Telefono: 0200619074
Telefono Cell: +39-3939890025 -- Fax: +39-0291390660
http://www.ziobudda.net ICQ: 58351764
http://www.ziobuddalabs.it Skype: zio_budda
http://www.ziodrupal.net MSN:
michel at ziobuddalabs.it
JABBER:
michel at ziobuddalabs.it
--
[ Drupal support list | http://lists.drupal.org/ ]
More information about the support
mailing list