cURL / Mailing Lists / curl-and-php / Single Mail

curl-and-php

POST an XML file via cURL and PHP

From: Alessandro Maestri <a.maestri_at_ops.tin.it>
Date: Mon, 16 Oct 2006 15:21:05 +0200

Hi all.

I've made a PHP file to POST a XML file via CURL and PHP.

This is the source:

<?php

$filename = "/home/prove/xml_di_esempio/file001.xml";
$handle = fopen($filename, "r");
$XPost = fread($handle, filesize($filename));
fclose($handle);

$url = "http://localhost/uploadNew/upload.php";

$ch = curl_init(); // initialize curl handle

curl_setopt($ch, CURLOPT_VERBOSE, 1); // set url to post to
curl_setopt($ch, CURLOPT_URL, $url); // set url to post to
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // return into a variable
curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml"));
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 40); // times out after 4s
curl_setopt($ch, CURLOPT_POSTFIELDS, $XPost); // add POST fields
curl_setopt($ch, CURLOPT_POST, 1);

$result = curl_exec($ch); // run the whole process

if (empty($result)) {
   // some kind of an error happened
   die(curl_error($ch));
   curl_close($ch); // close cURL handler
} else {
   $info = curl_getinfo($ch);
   curl_close($ch); // close cURL handler

   if (empty($info['http_code'])) {
           die("No HTTP code was returned");
   } else {
       // load the HTTP codes
       $http_codes = parse_ini_file("response.inc");
      
       // echo results
       echo "The server responded: \n";
       echo $info['http_code'] . " " . $http_codes[$info['http_code']];
   }
}

//echo $result; //contains response from server
?>

If I exec this file the POST don't send nothing to the server but I've
this output:

[tries_at_apdev01 xml_di_esempio]$ php post_via_curl.php
* About to connect() to localhost port 80
* Trying 127.0.0.1... * connected
* Connected to 127.0.0.1 (127.0.0.1) port 80
> POST /uploadNew/upload.php HTTP/1.1
Host: 127.0.0.1
Accept: */*
Content-Type: text/xml
Content-Length: 31104
Expect: 100-continue

< HTTP/1.1 100 Continue
< HTTP/1.1 200 OK
< Date: Mon, 16 Oct 2006 13:15:43 GMT
< Server: Apache/2.0.55 (Unix) mod_ssl/2.0.55 OpenSSL/0.9.8a PHP/5.1.2
< X-Powered-By: PHP/5.1.2
< Content-Length: 0
< Content-Type: text/html
* Connection #0 to host 127.0.0.1 left intact
* Closing connection #0
The server responded:
200 OK
[tries_at_apdev01 xml_di_esempio]$

I've read something about "Expect: 100-continue", but I don't understand
the problem. Can anyone explain better why I can't send via POST method
with my PHP file???

Thank's,
Alex.
_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
Received on 2006-10-16