Webmaster Forum
Go Back   Webmaster forum » ..:: Web Design ::.. » Script

Reply
 
Thread Tools Display Modes
  #1  
Old 24-09-2009
ravi72194 ravi72194 is offline
Member
 
Join Date: Jun 2009
Posts: 44
iTrader: (0)
ravi72194 is on a distinguished road
Smile Post XML through Socket

Here is a code to post xml through socket

<?php
function postXMLToURL ($server, $path, $xmlDocument) {
$contentLength = strlen($xmlDocument);
$fp = fsockopen($server, 80, $errno, $errstr, 30);
fputs($fp, "POST $path HTTP/1.0rn");
fputs($fp, "Host: $serverrn");
fputs($fp, "Content-Type: text/xmlrn");
fputs($fp, "Content-Length: $contentLengthrn");
fputs($fp, "Connection: closern");
fputs($fp, "rn"); // all headers sent
fputs($fp, $xmlDocument);
$result = '';
while (!feof($fp)) {
$result .= fgets($fp, 128);
}
return $result;
}
function getBody ($httpResponse) {
$lines = preg_split('/(rn|r|n)/', $httpResponse);
$responseBody = '';
$lineCount = count($lines);
for ($i = 0; $i < $lineCount; $i++) {
if ($lines[$i] == '') {
break;
}
}
for ($j = $i + 1; $j < $lineCount; $j++) {
$responseBody .= $lines[$j] . "n";
}
return $responseBody;
}
$xmlpacket ='<Required>
<Agency>
<Iata>56789</Iata>
<Agent>Thegetpr</Agent>
<P***word>myap***word</P***word>
<Brand>google.com</Brand>
</Agency>;
$result = postXMLtoURL("www.yoursitename.com", "/path/",$xmlpacket);
$responseBody = getBody($result);
echo $responseBody;
?>
Reply With Quote
Reply

Bookmarks

Tags
http, post, socket, xml

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 09:42 PM.


Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.