{"id":409,"date":"2009-08-28T19:34:33","date_gmt":"2009-08-28T19:34:33","guid":{"rendered":"http:\/\/www.phpmind.com\/blog\/?p=409"},"modified":"2010-07-17T01:35:44","modified_gmt":"2010-07-17T01:35:44","slug":"how-to-post-xml-using-curl","status":"publish","type":"post","link":"https:\/\/www.phpmind.com\/blog\/2009\/08\/how-to-post-xml-using-curl\/","title":{"rendered":"How to post XML using CURL?"},"content":{"rendered":"<p>Recently I was working in a hotel booking engine and found a couple of methods to post XML to server; I thought this might be good to share with my friends who want to post xml via HTTP POST method.<\/p>\n<p>There are several ways to Send XML requests via HTTP POST.<br \/>\nI am going to show you two ways. Both are very simple and easy.<\/p>\n<p>As first approach I have used a small xml file with CURL.<\/p>\n<pre lang=\"php\">\r\n\r\n<?php \r\n$xml_data ='<AATAvailReq1>'.\r\n    '<Agency>'.\r\n        '<Iata>1234567890<\/Iata>'.\r\n        '<Agent>lgsoftwares<\/Agent>'.\r\n        '<Password>mypassword<\/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'<HotelAvailReq1>'.\r\n'<DestCode>JHM<\/DestCode>'.\r\n        '<HotelCode>OGGSHE<\/HotelCode>'.\r\n        '<CheckInDate>101009<\/CheckInDate>'.\r\n        '<CheckOutDate>101509<\/CheckOutDate>'.\r\n        '<UseField>1<\/UseField>'.\r\n  '<\/HotelAvailReq1>'.  \r\n  '<\/AATAvailReq1>';\r\n\r\n\r\n$URL = \"https:\/\/www.yourwebserver.com\/path\/\";\r\n\r\n\t\t\t$ch = curl_init($URL);\r\n\t\t\tcurl_setopt($ch, CURLOPT_MUTE, 1);\r\n\t\t\tcurl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);\r\n\t\t\tcurl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);\r\n\t\t\tcurl_setopt($ch, CURLOPT_POST, 1);\r\n\t\t\tcurl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text\/xml'));\r\n\t\t\tcurl_setopt($ch, CURLOPT_POSTFIELDS, \"$xml_data\");\r\n\t\t\tcurl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);\r\n\t\t\t$output = curl_exec($ch);\r\n\t\t\tcurl_close($ch);\r\n\r\n?>\r\n<\/pre>\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Recently I was working in a hotel booking engine and found a couple of methods to post XML to server; I thought this might be good to share with my friends who want to post xml via HTTP POST method. There are several ways to Send XML requests via HTTP POST. I am going to [&hellip;]<\/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-409","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\/409","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=409"}],"version-history":[{"count":12,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/posts\/409\/revisions"}],"predecessor-version":[{"id":846,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/posts\/409\/revisions\/846"}],"wp:attachment":[{"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/media?parent=409"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/categories?post=409"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/tags?post=409"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}