0

I am trying to post xml to a server using cURL without any headers but I can't seem to get rid of the following headers:

Content-Disposition: form-data; name="data"; filename="tempData.xml".

Does anyone know how to remove these headers and just send the file?

Code is below:

$URL = www.myurl.com/process/php;

        //get post data
        $post = array("data"=>"@tempData.xml"); 

        //add headers
        /*$Headers = array
            ( "POST HTTP/1.0"
            , "Accept: text/xml"
            , "Content-type: text/xml"
            );*/

        //$Headers = array("");

        //create curl instance and set options
        $CH = curl_init($URL);
        curl_setopt( $CH, CURLOPT_TIMEOUT, 60 ); //timeout after 60 seconds
        curl_setopt( $CH, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt( $CH, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt( $CH, CURLOPT_HTTPHEADER, 0);
        curl_setopt( $CH, CURLOPT_HEADER, 0);
        curl_setopt( $CH, CURLOPT_POST, true );
        curl_setopt( $CH, CURLOPT_POSTFIELDS, $post ); // add post fields

        //echo curl_error($CH);
        $output = curl_exec( $CH );
        $info = curl_getinfo( $CH );
        //print_r($info);

        if($info['http_code'] != 200){
            //header('HTTP/1.0 500 Could Not Send XML');
            echo 'error ' . $info["http_code"];
            curl_close($CH);
            exit(1);
        }

        curl_close($CH)

;

4

1 回答 1

0

It isn't really possible if done like this.

When you select to do a multipart formpost with libcurl, it will actually do a formpost according to the spec. It was originally specified in RFC1867, and it did already then specify that the Content-Disposition: should be there for each form part.

If you want to do your own non-compliant post, then craft your own buffer completely instead of relying on libcurl's multipart formpost support.

Let me end up with saying that your commented out code that specifies custom headers is wrong since it includes a request line among the headers.

于 2013-02-15T21:08:53.370 回答