Menu
Hi !
I need do generate a XML document , something like this:
<USER>
<LOGIN>username</LOGIN>
<PASSWORD>userpass</PASSWORD>
</USER>
and send this to a document that is in [url]http://anywhere/scripts/somewebservice.dll/login
I’d like know how to create the xml document and how can i send this document to that URL. So, the program receive this xml and the login will happen.
Thanks in advance!
[code=html]
<?xml version="1.0" encoding=“ISO-8859-1” ?>
<users>
<user>
<login>User</login>
<password>Pass</password>
<forcelogin>value</forcelogin>
</user>
</users>
[/code]
fwrite($sock, "POST $service HTTP/1.0rn");
//fwrite($sock, "Host: secure.example.comrn");
fwrite($sock, "Content-type: application/x-www-form-urlencodedrn");
fwrite($sock, "Content-length: " . strlen($data) . "rn");
fwrite($sock, "Accept: */*rn");
fwrite($sock, "rn");
fwrite($sock, "$xmlrn");
fwrite($sock, "rn");
$headers = "";
while ($str = trim(fgets($sock, 4096)))
$headers .= "$strn";
echo "n";
$body = "";
while (!feof($sock))
$body .= fgets($sock, 4096);
fclose($sock);
return $body;
}
$USER = "loginhere";
$PASSWD = "passwdhere";
$service = "/scripts/SomeWebService.dll/login";
$xml = '<?xml version="1.0" encoding="ISO-8859-1" ?><USER><LOGIN>loginhere</LOGIN><PASSWORD>passwdhere</PASSWORD></USER>';
echo Communicate($xml,$service);
Don't worry about processing the XML, unless you start handling the inbound response. You have to see how the webservice handles the input (ie does it recognize login and password parameters).
Yes, use SOAP if that's what they're telling you to use. They should be providing you with the specifications that you need to follow as well.[/QUOTE]
i have to send xml via post method[/QUOTE]Ok... you need to send by the post method but as what? A string? A file? what? Where can we read the specs.
With such a cryptic reply how can anyone help you?http://anywhere/scripts/somewebservice.dll/login [/QUOTE]
[code=php]
<?php
// +-----------------------------------------------------------------------+
// | Copyright (c) 2002-2003, Richard Heyes |
// | All rights reserved. |
// | |
+-----------------------------------------------------------------------+
// | Author: Richard Heyes <[email protected]> |
// +-----------------------------------------------------------------------+
//
// $Id: Request.php,v 1.33 2003/10/26 10:28:28 avb Exp $
//
// HTTP_Request Class
//
// Simple example, (Fetches yahoo.com and displays it):
//
// $a = &new HTTP_Request('http://www.yahoo.com/');
// $a->sendRequest();
// echo $a->getResponseBody();
//
require_once('./Net/Socket.php');
require_once('./Net/URL.php');
define('HTTP_REQUEST_METHOD_GET', 'GET', true);
define('HTTP_REQUEST_METHOD_HEAD', 'HEAD', true);
define('HTTP_REQUEST_METHOD_POST', 'POST', true);
define('HTTP_REQUEST_METHOD_PUT', 'PUT', true);
define('HTTP_REQUEST_METHOD_DELETE', 'DELETE', true);
define('HTTP_REQUEST_METHOD_OPTIONS', 'OPTIONS', true);
define('HTTP_REQUEST_METHOD_TRACE', 'TRACE', true);
define('HTTP_REQUEST_HTTP_VER_1_0', '1.0', true);
define('HTTP_REQUEST_HTTP_VER_1_1', '1.1', true);
class HTTP_Request {
/**
* Full url
* @var string
*/
var $_url;
*/
function HTTP_Request($url, $params = array())
{
$this->_sock = &new Net_Socket();
$this->_method = HTTP_REQUEST_METHOD_GET;
$this->_http = HTTP_REQUEST_HTTP_VER_1_1;
$this->_requestHeaders = array();
$this->_postData = null;
$this->_user = null;
$this->_pass = null;
$this->_proxy_host = null;
$this->_proxy_port = null;
$this->_proxy_user = null;
$this->_proxy_pass = null;
$this->_allowRedirects = false;
$this->_maxRedirects = 3;
$this->_redirects = 0;
$this->_timeout = null;
$this->_response = null;
foreach ($params as $key => $value) {
$this->{'_' . $key} = $value;
}
$this->setURL($url);
// Default useragent
$this->addHeader('User-Agent', 'PEAR HTTP_Request class ( http://pear.php.net/ )');
// Default Content-Type
$this->addHeader('Content-Type', 'application/x-www-form-urlencoded');
// Make sure keepalives dont knobble us
$this->addHeader('Connection', 'close');
// Basic authentication
if (!empty($this->_user)) {
$this->_requestHeaders['Authorization'] = 'Basic ' . base64_encode($this->_user . ':' . $this->_pass);
}
// Use gzip encoding if possible
if (HTTP_REQUEST_HTTP_VER_1_1 == $this->_http && extension_loaded('zlib')) {
$this->addHeader('Accept-Encoding', 'gzip');
}
}
.... //all the function here
/**
* Notifies all registered listeners of an event.
*
* @param string Event name
* @param mixed Additional data
* @access private
* @see HTTP_Request::_notify()
*/
function _notify($event, $data = null)
{
foreach (array_keys($this->_listeners) as $id) {
$this->_listeners[$id]->update($this, $event, $data);
}
}
} // End class HTTP_Response
?>
[/code]
[code=php]
$XML = $XML_HEADER;
$XML .= "<USER>";
$XML .= "<LOGIN>$login</LOGIN>";
$XML .= "<PASSWORD>$pass</PASSWORD>";
$XML .= "</USER>";
// logando no WebService
require_once('Request.php');
$Response = '';
$Req = &new HTTP_Request($WebService . 'login');
$Req->setMethod(HTTP_REQUEST_METHOD_POST);
$Req->clearPostData();
$Req->addRawPostData($XML,True);
$Req->sendRequest();
$Response = $Req->getResponseBody();
[/code]
0.1.9 — BETA 5.18