Re: file upload, Content-Type problem

Nicolas Rod <[email protected]>
Newsgroups gmane.comp.web.curl.php
Message-ID <[email protected]>
Hi,

Yes I tried it, but it gives me this curl error: "failed creating
formpost data".

Any other idea ?


-------- Message initial --------
De: Joshua Cooke <[email protected]>
Reply-to: curl with PHP <[email protected]>
À: curl with PHP <[email protected]>
Sujet: Re: file upload, Content-Type problem
Date: Wed, 28 Oct 2009 17:39:30 +0000


Have you tried this?

$post_data = array('file' => '@/tmp/content.xml;type=text/xml');


Nicolas Rod wrote:
> 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
>   

_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php


--------------------------------------
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.