curl-and-php
file upload, Content-Type problem
Date: Wed, 28 Oct 2009 17:58:08 +0100
Hi,
I'm trying to simulate an HTML upload form in order to send a request to
a REST service, and I'm facing a problem with the body content of the
request.
I have to send an XML file to the service. After having tried a lot of
things in my PHP code, I tried to send the XML file by using the 'curl'
client in a Linux terminal and succeeded. This allowed me to inspect the
data that are sent by sniffing my network, and I found a difference that
seems to be the problem.
***********************************************************************************
With the command line, in order to make it work, I had to use the -F
option, with the name of the file + the type of the file:
curl -F file="@content.xml;type=text/xml"
"http://www.my-rest-service.com"
(...)
Content-Type: multipart/form-data;
boundary=----------------------------ea2a22a059af
(...)
----------------------------ea2a22a059af
Content-Disposition: form-data; name="file"; filename="content.xml"
Content-Type: text/xml
<?xml version="1.0" encoding="UTF-8"?>
(...)
----------------------------ea2a22a059af
***********************************************************************************
But with the following PHP code:
$post_data = array('file' => '@/tmp/content.xml');
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);
(...)
Content-Type: multipart/form-data;
boundary=----------------------------d795ec2deb5c
(...)
------------------------------d795ec2deb5c
Content-Disposition: form-data; name="file"; filename="content.xml"
Content-Type: application/octet-stream
<?xml version="1.0" encoding="UTF-8"?>
(...)
------------------------------d795ec2deb5c
***********************************************************************************
As you can see, the value of the Content-Type is different
curl client from a terminal :
------------------------------------
Content-Type: text/xml
CURL-PHP :
--------------
Content-Type: application/octet-stream
Is there a way to set the value of this Content-Type with CURL-PHP ?
Thanks a lot,
Nicolas
--------------------------------------
Nicolas Rod
Université de Genève - DINF/NTICE
Uni-Dufour, bureau 335
Rue Général-Dufour 24
1204 Genève
Tel. +41 22 379 11 19
--------------------------------------
_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
Received on 2009-10-28