php cURL no acepta mi tipo de contenido

I'm trying to use cURL to upload a file using PUT with a content type of application/octet-stream, but even when I set it using curl_setopt the content type is always 'text/html'. I've tested in firefox and chrome to see if it as a browser quirk or something (it wasn't) so I'm not sure what I can do about this.

    ini_set('display_errors', 1);
            $ch = curl_init();
            $localfile = 'upload.txt';
            $fp = fopen($localfile, 'r');
            curl_setopt($ch, CURLOPT_URL, $url.$localfile.'?type=file');
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
            curl_setopt($ch, CURLOPT_HEADER, true);
            curl_setopt($ch, CURLOPT_HTTPHEADER, array("content-type: application/octet-stream"));
            curl_setopt($ch, CURLOPT_UPLOAD, 1);
            curl_setopt($ch, CURLOPT_INFILE, $fp);
            curl_setopt($ch, CURLOPT_INFILESIZE, filesize($localfile));
            curl_setopt($ch, CURLOPT_USERPWD, $un.":".$pw);
            curl_setopt($ch, CURLOPT_VERBOSE, 1);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
            $msg = curl_exec ($ch);
            $error_no = curl_errno($ch);
            $print = curl_getinfo($ch);
            curl_close ($ch);
            if ($error_no == 0) {
                    $error = 'File uploaded succesfully.';
            } else {
                    $error = 'File upload error.';

Gracias por leer.

preguntado el 12 de septiembre de 13 a las 03:09

Inténtalo de nuevo con Content-Type en lugar de content-type. Maybe you need to add Content-Length too, I don't know if cURL will add this automatically. -

@Havenard What value would I use for content length? -

The exact length in bytes of the file you are trying to upload. -

@Havenard I added content-length and tried the content-type capitalization, didn't work. -

I suggest you try to perform this operation using a browser and then compare in the web server logs what cURL is trying to do and what the browser did after some difference. Perhaps some network debugging tool like Wireshark might help too. -

0 Respuestas

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.