2013-10-01 13 views
92

Ho usato questa sintassi per inviare un file insieme ad alcuni parametri:Qual è il modo corretto per POST multipart/form-data usando curl?

curl -v -include --form "key1=value1" --form upload=localfilename URL 

Il file è di circa 500K di dimensione. Prima di tutto, vedo che la lunghezza del contenuto è 254 sul lato di trasmissione. Più tardi la lunghezza del contenuto della risposta del server è 0. Dove sto andando male?

Ecco la traccia completa del comando.

* Couldn't find host xxx.xxx.xxx.xxx in the _netrc file; using defaults 
* About to connect() to xxx.xxx.xxx.xxx port yyyy (#0) 
* Trying xxx.xxx.xxx.xxx... 
* Adding handle: conn: 0x4b96a0 
* Adding handle: send: 0 
* Adding handle: recv: 0 
* Curl_addHandleToPipeline: length: 1 
* - Conn 0 (0x4b96a0) send_pipe: 1, recv_pipe: 0 
* Connected to xxx.xxx.xxx.xxx (xxx.xxx.xxx.xxx) port yyyy (#0) 
* POST /zzzzzz/UploadFile HTTP/1.1 
* User-Agent: curl/7.32.0 
* Host: xxx.xxx.xxx.xxx:yyyy 
* Accept: */* 
* Content-Length: 254 
* Expect: 100-continue 
* Content-Type: multipart/form-data; boundary=------------------------948a6137eef50079 
* 
* HTTP/1.1 100 Continue 
* HTTP/1.1 100 Continue 

* HTTP/1.1 200 OK 
* HTTP/1.1 200 OK 
* Server Apache-Coyote/1.1 is not blacklisted 
* Server: Apache-Coyote/1.1 
* Server: Apache-Coyote/1.1 
* Added cookie JSESSIONID="C1D7DD042E250211D9DEA82688876F88" for domain xxx.xxx.xxx.xxx, path /zzzzz/, expire 0 
* Set-Cookie: JSESSIONID=C1D7DD042E250211D9DEA82688876F88; Path=/zzzzzz/; 
* HttpOnly 
* Set-Cookie: JSESSIONID=C1D7DD042E250211D9DEA82688876F88; Path=/zzzzzz/; HttpOnly 
* Content-Type: text/html;charset=ISO-8859-1 
Content-Type: text/html;charset=ISO-8859-1 
* Content-Length: 0 
* Content-Length: 0 
* Date: Tue, 01 Oct 2013 11:54:24 GMT 
* Date: Tue, 01 Oct 2013 11:54:24 GMT 
* Connection #0 to host xxx.xxx.xxx.xxx left intact 
+0

possibile duplicato di [ Utilizzo di arricciatura per caricare i dati POST con i file] (http://stackoverflow.com/questions/12667797/using-curl-to-upload-post-data-with-files) –

risposta

146

la seguente sintassi fissa per voi:

curl -v -F key1=value1 -F [email protected] URL 
+14

Invece di --form, si può usare -F (maiuscolo richiesto) per una riga di comando più breve. –

+0

che dire di Windows & curl.exe? – Piotr

+0

e di più allegati? – hellboy

7

di caricare un file utilizzando ricciolo in Windows ho scoperto che il percorso richiede sfuggito virgolette

esempio

curl -v -F '[email protected]\"C:/myfile.txt\"' URL 
-1

In Windows 10, ricciolo 7.28.1 all'interno di PowerShell, ho trovato quanto segue per lavorare per me:

$filePath = "c:\temp\dir with spaces\myfile.wav" 
$curlPath = ("[email protected]" + $filePath) 
curl -v -F $curlPath URL 
Problemi correlati