title: CURL multipart form post - HTTP error before end of send, stop sending
body: <p>I am sending a multipart form POST via CURL from Linux shell script. The request works fine in Postman but from CURL it fails with:</p>
  
  <pre><code>Internal Server Error
  </code></pre>
  
  <p>then</p>
  
  <pre><code>HTTP error before end of send, stop sending
  </code></pre>
  
  <p>I even copy the Curl for Linux Shell code directly from Postman and paste into the shell script, so it should be exactly the same request that Postman is making.</p>
  
  <p>Here is the command:</p>
  
  <pre><code>curl --request POST \
    --no-alpn \
    --url https://XXXXXXXXXXX/api/v1.0/XXXXX/XXXXXX/XXXXX \
    --header 'accept: text/plain' \
    --header 'cache-control: no-cache' \
    --header 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' \
    --header 'sessionid: $session_id' \
    --form filename=XXXXXX.zip \
    --form XXXXXX=XXXXXX \
    --form file=@$file_path \
    --trace-ascii /dev/stdout || exit $?
  }
  </code></pre>
  
  <p>And here is the log from --trace-ascii:</p>
  
  <pre><code>https://XXXXXXXXXXXXXXXXX/api/v1.0/XXXXXX/XXXXX/XXXXXXXXX
  Note: Unnecessary use of -X or --request, POST is already inferred.
    % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                   Dload  Upload   Total   Spent    Left  Speed
  
    0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0== Info:   Trying XXX.XXX.XXX.XXXX...
  == Info: Connected to XXXXXXXXXXXXXXXX.com (XX.XX.XX.XX) port 443 (#0)
  == Info: found 148 certificates in /etc/ssl/certs/ca-certificates.crt
  == Info: found 592 certificates in /etc/ssl/certs
  == Info: SSL connection using TLS1.2 / ECDHE_RSA_AES_128_GCM_SHA256
  == Info:     server certificate verification OK
  == Info:     server certificate status verification SKIPPED
  == Info:     common name: *.XXXXXX.com (matched)
  == Info:     server certificate expiration date OK
  == Info:     server certificate activation date OK
  == Info:     certificate public key: RSA
  == Info:     certificate version: #3
  == Info:     subject: OU=Domain Control Validated,CN=*.XXXXXX.com
  == Info:     start date: Mon, 15 Aug 2016 08:23:38 GMT
  == Info:     expire date: Thu, 15 Aug 2019 08:23:38 GMT
  == Info:     issuer: C=US,ST=Arizona,L=Scottsdale,O=GoDaddy.com\, Inc.,OU=http://certs.godaddy.com/repository/,CN=Go Daddy Secure Certificate Authority - G2
  == Info:     compression: NULL
  =&gt; Send header, 363 bytes (0x16b)
  0000: POST /XXXXX/api/v1.0/XXXXXX/upload/XXXXXX HTTP/1.1
  003b: Host: XXXXXX.XXXXXXX.com
  0059: User-Agent: curl/7.47.0
  0072: accept: text/plain
  0086: cache-control: no-cache
  009f: sessionid: $session_id
  00b7: Content-Length: 1639
  00cd: Expect: 100-continue
  00e3: content-type: multipart/form-data; boundary=----WebKitFormBounda
  0123: ry7MA4YWxkTrZu0gW; boundary=------------------------b059847fb557
  0163: a899
  0169: 
  &lt;= Recv header, 23 bytes (0x17)
  0000: HTTP/1.1 100 Continue
  =&gt; Send data, 387 bytes (0x183)
  0000: --------------------------b059847fb557a899
  002c: Content-Disposition: form-data; name="filename"
  005d: 
  005f: xxxxxxxxxx.zip
  006b: --------------------------b059847fb557a899
  0097: Content-Disposition: form-data; name="XXXXXXXXXXX"
  00cc: 
  00ce: XXXXXXXXXXXXXXXXXXXX
  00ea: --------------------------b059847fb557a899
  0116: Content-Disposition: form-data; name="file"; filename="XXXXXX.zip
  0156: "
  0159: Content-Type: application/octet-stream
  0181: 
  =&gt; Send data, 1204 bytes (0x4b4)
  0000: PK........r~.K..D!....p.......output/XXXXXXX.XXXXX.....7Z..7Zux...
  0040: ............{LSW....@.!`.9. F..Eh+.......JA..W.2.V...A.%&gt;... #Q1
  0080: T.....{Nb.]&amp;..1.3M|.........w..z.]8..I.I&gt;.....n?...\hM/.h..?oy^.
  00c0: ..... ..:.&gt;J..Q...N...*A...l`...."..N...@.P'........d..._.....L
  0100: .].......z....N6.B......Y5t...Zd.V...}..l...........EC..$..e...W
  0140: .V`.lV...p..d._.....S...............d`.l..}.....f[...{....`....M
  0180: .....kN..[.4.2w.9.bN....q.8.'.K.......'..~........sI.....K...s.
  01c0: ...U.'..d,.......&gt;......T.5....|.$,)o'bIy{...pN.....K.o..[..cWp.
  0200: c.@..B.S........d.I..P./.F..0....=4.......d..#{K$..#.^=.......
  0240: *....Bi...i....8j!T......|.Ld...x....&gt;......A...|.I.}&gt;.....Yt=..
  0280: ..Tp.q...O&amp;.. .....Ac..V....a......f.G...!x.f.i.gu}.2i.4....NK..
  02c0: .G;..k~......=*....g..c#..c.M.oW........-...vW.~#u...#....cz.bu=
  0300: .."Bs.js\.z.1.....&amp;|.MV..&lt;a"4...IqRO.kKC.v.Gz.....].G.\.|...:om
  0340: .C.v5G..X].kw..\....R/.........C.X].5&lt;.B.\'....z.O|@.v.P\......
  0380: ^...f~........9....YG~fum}....^,K.......F.vmIl....hI."h.FM.....f
  03c0: ....Z...`um.}E...1;......_....yF.xV...BDh...U..z...*.o.`O..V.W.6
  0400: ..kf.n...*.{..].].c~.w~K......4I.k.Y.....r.wV.................F
  0440: .v..O..OPK..........r~.K..D!....p.....................output/xxxxxxx
  .mldUT.....7Zux.............PK..........V...H.....
  =&gt; Send data, 48 bytes (0x30)
  0000: 
  0002: --------------------------b059847fb557a899--
  &lt;= Recv header, 36 bytes (0x24)
  0000: HTTP/1.1 500 Internal Server Error
  &lt;= Recv header, 15 bytes (0xf)
  0000: Server: nginx
  &lt;= Recv header, 37 bytes (0x25)
  0000: Date: Mon, 18 Dec 2017 15:15:56 GMT
  &lt;= Recv header, 26 bytes (0x1a)
  0000: Content-Type: text/plain
  &lt;= Recv header, 28 bytes (0x1c)
  0000: Transfer-Encoding: chunked
  &lt;= Recv header, 24 bytes (0x18)
  0000: Connection: keep-alive
  
  100  1639    0     0  100  1639      0   2269 --:--:-- --:--:-- --:--:--  2266&lt;= Recv header, 29 bytes (0x1d)
  0000: X-FRAME-OPTIONS: SAMEORIGIN
  &lt;= Recv header, 83 bytes (0x53)
  0000: Set-Cookie: JSESSIONID=XXXXXXXXXXXXXXXXXXXXXXXX; Path=/;
  0040:  Secure; HttpOnly
  == Info: HTTP error before end of send, stop sending
  &lt;= Recv header, 2 bytes (0x2)
  0000: 
  &lt;= Recv data, 106 bytes (0x6a)
  0000: 64
  0004: &lt;ErrorResponse&gt;&lt;key/&gt;&lt;localizedMessage/&gt;&lt;httpError&gt;Internal Serv
  0044: er Error&lt;/httpError&gt;&lt;/ErrorResponse&gt;
  &lt;= Recv data, 5 bytes (0x5)
  0000: 0
  0003: 
  </code></pre>
  
  <p>I should add that the CURL command is being run from a Docker container.</p>