I'm trying to post an xml but I don't know why the solution below works. The documentation says that I should use the '@' plus filepath to upload file, but it does no work. So I did in this way:
<?php
$url = 'http://localhost:8080/solr/update/?commit=true';
$file = realpath('/home/fabio/target_file.xml');
$header = array(
"Content-Type: text/xml",
);
$post = file_get_contents($file);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
echo curl_exec($ch);
curl_close($ch);
And I got this OK (200) status:
* Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 8080 (#0)
> POST /solr/update/?commit=true HTTP/1.1
Host: localhost:8080
Accept: */*
Content-Type: text/xml
Content-Length: 3502
Expect: 100-continue
< HTTP/1.1 100 Continue
* We are completely uploaded and fine
< HTTP/1.1 200 OK
< Server: Apache-Coyote/1.1
< Content-Type: application/xml;charset=UTF-8
< Transfer-Encoding: chunked
< Date: Tue, 19 Jan 2016 16:52:19 GMT
<
* Connection #0 to host localhost left intact
<?xml version="1.0" encoding="UTF-8"?>
<response>
<lst name="responseHeader"><int name="status">0</int><int name="QTime">269</int></lst>
</response>