2012-02-03 15 views
23

Básicamente, estoy tratando de escribir una serie de guiones para interactuar con Dot Net Nuke. He estado analizando el tráfico y ahora puedo iniciar sesión y realizar algunas tareas básicas. Sin embargo, nunca he manejado la carga de archivos binarios con curl. ¿Alguien estaría dispuesto a mirar esto para ayudarme? Aquí está la anatomía de la solicitud:Publicación de datos binarios con curl

http://pastebin.com/qU8ZEMaQ

Esto es lo que tengo para el rizo hasta el momento:

http://pastebin.com/LG2ubFZG

de edición: Para los perezosos -

longitud de la el archivo se logra y se almacena en LONGITUD Bullshit es solo copiar/pegar de la URL de solicitud con parámetros, menos la URL misma.

curl -L --cookie ~/.cms --data-binary "@background.jpg" \ 
--header "Content-Length: $LENGTH" \ 
--header "Content-Disposition: form-data" \ 
--header "name=\"RadFileExplorer1_upload1file0\"" \ 
--header "Content-Type: image/jpg" \ 
--header "Filename=\"background.jpg\"" \ 
--data $BULLSHIT \ 
--referer "Kept-Secret" \ 
"Kept-Secret" 

Respuesta

46

No es necesario --header "Content-Length: $ LONGITUD".

Mire por ejemplo para Google ejemplo:

http://code.google.com/apis/gdata/articles/using_cURL.html#creating-entries

 
curl --request POST --data-binary "@template_entry.xml" $URL 

Tenga en cuenta que la solicitud GET no soporta la transferencia de datos.

Recuerde también que la solicitud POST tiene 2 esquemas de codificación diferentes. Esta es la primera forma:

 
    $ nc -l -p 6666 & 
    $ curl --request POST --data-binary "@README" http://localhost:6666 

POST/HTTP/1.1 
User-Agent: curl/7.21.0 (x86_64-pc-linux-gnu) libcurl/7.21.0 OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.15 libssh2/1.2.6 
Host: localhost:6666 
Accept: */* 
Content-Length: 9309 
Content-Type: application/x-www-form-urlencoded 
Expect: 100-continue 

.. -*- mode: rst; coding: cp1251; fill-column: 80 -*- 
.. rst2html.py README README.html 
.. contents:: 

Es probable que solicita esta:

 
-F/--form name=content 
      (HTTP) This lets curl emulate a filled-in form in 
       which a user has pressed the submit button. This 
       causes curl to POST data using the Content- Type 
       multipart/form-data according to RFC2388. This 
       enables uploading of binary files etc. To force the 
       'content' part to be a file, prefix the file name 
       with an @ sign. To just get the content part from a 
       file, prefix the file name with the symbol . The 
       difference between @ and is then that @ makes a 
       file get attached in the post as a file upload, 
       while the makes a text field and just get the 
       contents for that text field from a file. 
+0

Gracias por su respuesta. Lamentablemente, nada logra suceder. ¿Sería posible que eches un vistazo rápido a la anatomía de la publicación? ¿Cómo agregaría algo como: '------ WebKitFormBoundarymXQVUy6BiZBV3AxA Content-Disposition: form-data; name = "RadFileExplorer1 $ currentFolder" /Portals/0/Images/Test/'a un comando Curl? ¿Sería eso a través del encabezado? ¿O dado que tiene un nombre sería a través de datos de publicación regulares? –

+0

Como recuerdo correctamente para la solicitud POST, existe un esquema de codificación diferente (¿puede administrarse la etiqueta FORM html?). – gavenkoa

+0

Bueno, normalmente con curl puedes decir algo como curl -d "username = cheese & password = 123456" , pero también se ve drásticamente diferente cuando lo inspecciono con Chrome/Firebug. Ciertamente no veo Content-Disposition entre otras cosas. No sé si debe haber una versión especial de datos POST cuando envíe datos en texto plano y binarios. –