Re: [SOAP] simple post of xml
| From: | David Busby | Date: | Tue, 17 Dec 2002 19:38:02 +0000 |
| Subject: | Re: [SOAP] simple post of xml | ||
| References: | 1 | Groups: | php.soap |
| Request: | Send a blank email to php-soap+get-335@lists.php.net to get a copy of this message | ||
function soap_send($xml, $url)
{
$ar_u = parse_url($url);
$req = "POST ".$ar_u['path']." HTTP/1.0\r\n";
$req .= "Accept: */*\r\n";
$req .= "Connection: close\r\n";
$req .= "Content-Length: ".strlen($xml)."\r\n";
$req .= "Content-Type: text/xml\r\n";
$req .= "Host: ".$ar_u['host']."\r\n";
$req .= "User-Agent: Edoceo Simple Soap/0.1\r\n";
$req .= "\r\n";
$req .= $xml;
// Create TCP/IP Socket
$socket = socket_create (AF_INET, SOCK_STREAM, 0);
if ($socket < 0) {
echo "socket_create() failed: reason: " . socket_strerror ($socket) .
"\n";
}
// Connect
$address = gethostbyname($ar_u['host']);
$service_port = 80;
//echo "Attempting to connect to '$address' on port
'$service_port'...";
$result = socket_connect ($socket, $address, $service_port);
if ($result < 0) {
echo "socket_connect() failed.\nReason: ($result) " .
socket_strerror($result) . "\n";
}
// Send
//echo "Sending HTTP request...";
socket_write ($socket, $req, strlen($req));
// Receive
while ($out = socket_read ($socket, 2048)) {
$ret .= $out;
}
// Close Socket
socket_close ($socket);
// Only give back XML
$i = strpos($ret, "\r\n\r\n") + 4;
return substr($ret, $i);
}
----- Original Message -----
From: "Jay Chou @ Knowledgemicro.com" <jay@knowledgemicro.com>
To: <soap@lists.php.net>
Sent: Tuesday, December 17, 2002 11:29
Subject: [SOAP] simple post of xml
> Hi,
>
> I am trying to use PHP to post a simple XML stream to an URL. Coming
> primarily from a Microsoft background, I'm used to calling a component
> such as XMLHTTP that would take care of sending and receiving XML. Is
> there something like or a function in PHP? from looking around the web,
> I think I may have to use socket functions but I hope not. thankx
>