[bash] Binary Data Posting with curl

So basically, I'm trying to write a series of scripts to interact with Dot Net Nuke. I've been analysing the traffic and can now login and do some basic tasks. However, I've never handled binary file upload with curl. Would someone be willing to look at this to help me out? Here's the anatomy of the request:

http://pastebin.com/qU8ZEMaQ

Here's what I've got for curl so far:

http://pastebin.com/LG2ubFZG

edit: For the lazy -

length of the file is achieved and stored in LENGTH
STUFF is just a copy/paste of the request URL with parameters, minus the URL itself.

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 $STUFF \
--referer "Kept-Secret" \
"Kept-Secret"

This question is related to bash post curl dotnetnuke binary-data

The answer is


You don't need --header "Content-Length: $LENGTH".

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

Note that GET request does not support content body widely.

Also remember that POST request have 2 different coding schema. This is first form:

  $ 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::

You probably request this:

-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.

Examples related to bash

Comparing a variable with a string python not working when redirecting from bash script Zipping a file in bash fails How do I prevent Conda from activating the base environment by default? Get first line of a shell command's output Fixing a systemd service 203/EXEC failure (no such file or directory) /bin/sh: apt-get: not found VSCode Change Default Terminal Run bash command on jenkins pipeline How to check if the docker engine and a docker container are running? How to switch Python versions in Terminal?

Examples related to post

How to post query parameters with Axios? How can I add raw data body to an axios request? HTTP POST with Json on Body - Flutter/Dart How do I POST XML data to a webservice with Postman? How to set header and options in axios? Redirecting to a page after submitting form in HTML How to post raw body data with curl? How do I make a https post in Node Js without any third party module? How to convert an object to JSON correctly in Angular 2 with TypeScript Postman: How to make multiple requests at the same time

Examples related to curl

What is the incentive for curl to release the library for free? curl: (35) error:1408F10B:SSL routines:ssl3_get_record:wrong version number Converting a POSTMAN request to Curl git clone error: RPC failed; curl 56 OpenSSL SSL_read: SSL_ERROR_SYSCALL, errno 10054 How to post raw body data with curl? Curl : connection refused How to use the curl command in PowerShell? Curl to return http status code along with the response How to install php-curl in Ubuntu 16.04 curl: (35) SSL connect error

Examples related to dotnetnuke

jquery change button color onclick Binary Data Posting with curl The SELECT permission was denied on the object 'sysobjects', database 'mssqlsystemresource', schema 'sys'

Examples related to binary-data

How to build PDF file from binary string returned from a web-service using javascript best way to preserve numpy arrays on disk Binary Data Posting with curl Best way to read a large file into a byte array in C#? How do you embed binary data in XML?