{"id":412,"date":"2009-08-28T19:47:35","date_gmt":"2009-08-28T19:47:35","guid":{"rendered":"http:\/\/www.phpmind.com\/blog\/?p=412"},"modified":"2010-07-17T01:35:44","modified_gmt":"2010-07-17T01:35:44","slug":"how-to-post-xml-using-socket","status":"publish","type":"post","link":"https:\/\/www.phpmind.com\/blog\/2009\/08\/how-to-post-xml-using-socket\/","title":{"rendered":"How to post XML using socket ?"},"content":{"rendered":"<p>I had discussed posting XML over HTTP using CURL in last post. Remember that was first method.<br \/>\nAs I had promised on earlier post I would like to share second method with you. That is socket!!<br \/>\nUse this code and send your XML file.<\/p>\n<pre lang=\"php\">\r\n<?php\r\nfunction postXMLToURL ($server, $path, $xmlDocument) {\r\n$contentLength = strlen($xmlDocument);\r\n$fp = fsockopen($server, 80, $errno, $errstr, 30);\r\nfputs($fp, \"POST $path HTTP\/1.0rn\");\r\nfputs($fp, \"Host: $serverrn\");\r\nfputs($fp, \"Content-Type: text\/xmlrn\");\r\nfputs($fp, \"Content-Length: $contentLengthrn\");\r\nfputs($fp, \"Connection: closern\");\r\nfputs($fp, \"rn\"); \/\/ all headers sent\r\nfputs($fp, $xmlDocument);\r\n$result = '';\r\nwhile (!feof($fp)) {\r\n$result .= fgets($fp, 128);\r\n}\r\nreturn $result;\r\n}\r\n\r\nfunction getBody ($httpResponse) {\r\n$lines = preg_split('\/(rn|r|n)\/', $httpResponse);\r\n$responseBody = '';\r\n$lineCount = count($lines);\r\nfor ($i = 0; $i < $lineCount; $i++) {\r\nif ($lines[$i] == '') {\r\nbreak;\r\n}\r\n}\r\nfor ($j = $i + 1; $j < $lineCount; $j++) {\r\n$responseBody .= $lines[$j] . \"n\";\r\n}\r\nreturn $responseBody;\r\n}\r\n\r\n$xmlpacket ='<AATHtlDispReq1>\r\n<Agency>\r\n<Iata>1234567890<\/Iata>\r\n<Agent>lgsoftwares<\/Agent>\r\n<Password>myapassword<\/Password>\r\n<Brand>phpmind.com<\/Brand>\r\n<\/Agency>\r\n<Passengers>\r\n<Adult AGE=\"\" ID=\"1\"><\/Adult>\r\n<Adult AGE=\"\" ID=\"2\"><\/Adult>\r\n<\/Passengers>\r\n<DestCode>OGG<\/DestCode>\r\n<CheckInDate>101009<\/CheckInDate>\r\n<\/AATHtlDispReq1>';\r\n\r\n\r\n$result = postXMLtoURL(\"www.yourdomain.com\", \"\/path\/\",$xmlpacket);\r\n\r\n$responseBody = getBody($result);\r\n\r\necho $responseBody;\r\n?>\r\n\r\n<\/pre>\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I had discussed posting XML over HTTP using CURL in last post. Remember that was first method. As I had promised on earlier post I would like to share second method with you. That is socket!! Use this code and send your XML file.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[3,21],"tags":[],"class_list":["post-412","post","type-post","status-publish","format-standard","hentry","category-php","category-php-xml"],"_links":{"self":[{"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/posts\/412","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/comments?post=412"}],"version-history":[{"count":11,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/posts\/412\/revisions"}],"predecessor-version":[{"id":845,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/posts\/412\/revisions\/845"}],"wp:attachment":[{"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/media?parent=412"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/categories?post=412"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/tags?post=412"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}