Posting XML from PHP

There is a frequent need to post xml data to a url. Below is shown an example which lets you post xml data using CURL.


Download code

This site is a digital habitat of Sameer Borate, a freelance web developer working in PHP, MySQL and WordPress. I also provide web scraping services, website design and development and integration of various Open Source API's. Contact me at metapix[at] for any new project requirements and price quotes.

8 Responses



May 12th, 2010 at 5:03 am

Excellent example. Clear, short, sweet and awesome handwriting font to boot. What font is that?



June 5th, 2010 at 5:23 am

Wow excellent script but am getting error message “Bad Request (Invalid URL)” am using IP instead domain on URL

can you help me what went wrong?



August 25th, 2012 at 12:40 pm

I’m getting the same error. Bad Request (Invalid URL)


mike murray

September 14th, 2012 at 3:27 pm

Hello. I’m very na├»ve to the idea of HTML, XML, and such. I was wondering if you could simply tell me how to take an XML feed or an HTML feed and automatically have it go to a post on my page? I have it set up already where e-mails automatically go to post, but I would really like to be able to take XML feeds from sports pages and have those automatically go to my posts. I hope I’m not sounding too stupid as I come from the day where I used to set the VCR for my dad. You can e-mail me back at the address I provided and I hope that you might build to provide me with an explanation. I can understand. Thank you very much for your time


Echoing PHP Variable inside XML | - Developers Network

September 19th, 2012 at 10:27 am

[…] was using this link to figure it out: Sep 19, 2012 No Comments » Posted in PHP […]



November 5th, 2012 at 8:56 am

There is an error in your header options. After POST the uri is expected.
So if you omit the headers apart from content-type everything works as expected.
Or use this instead.


real estate office management

December 26th, 2012 at 2:03 pm

Heya just wanted to give you a brief heads up and let you know
a few of the images aren’t loading properly. I’m
not sure why but I think its a linking issue.
I’ve tried it in two different internet browsers and both show the same results.


Erik Bortscht

February 2nd, 2015 at 3:54 am

I used this method on a Apache Tomcat/7.0.16 webserver as target and always got the response 505 (unsupported http protocol version). Turned out the culprit was the extra space in
“HTTP/1.0 \r\n”.

Your thoughts