How to http post raw data in php

This example shows how to post raw data over http in php. For exemple if you want to send an XML-document to a web service.

$xmlData = ‘…’;

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, ‘http://example.com/service.php’);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(“Content-Type: application/xml”));
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $xmlData);
curl_setopt($curl, CURLOPT_HEADER, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec ($curl);
curl_close ($curl);

The variable $response now contains the server response.

Hello, world!

So this is my new blog. My first blog. One of the main reasons for starting this blog is for me to have a database for all kinds of information that I may need again some day. Let’s see what comes…

Btw, although I am not an native english speaker I have planned to write my posts in english. Hope this helps to improve my english language skills. This is one of the other things I’m interested in.