Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

(The following is backstory, you can jump down to "Question:" if you'd like)

There's a webpage for one of my courses that accepts input text (expected to be Python code) and then gives some tokenized response. It's meant to be used as a reference for the Python lexers we're writing. I'm trying to automate my testing process and be able to check my code without opening a browser, copying text back and forth, etc. So here's what I'm trying to do:

I've got a sample python file named "" and I want to post it to the server as if I had filled out that form. I've tried:

curl --data-urlencode ""

But unfortunately, that's not working right because apparently "" is getting posted as my file contents (that is, "" is what's getting posted, not "file=<>"). I've tried --form and --data but those haven't worked either.

Question: Specifically, if I have a file with non-url-encoded contents, and the contents of this file needs to be part of a POST and associated with a particular name (in this case, file), what's the correct way of accomplishing this?

share|improve this question
Just found one way to do it: "file=`cat`" – Cornstalks Jan 30 '13 at 3:17
Why not post that as an answer? You can answer your own question, and then in ~2 days or something (not sure how long) you can accept it. – BenjiWiebe Jan 30 '13 at 3:34
@BenjiWiebe: Alright, I'll post it. – Cornstalks Jan 30 '13 at 3:39
up vote 19 down vote accepted

What you want is "" (no =).

From the curl manpage:

name@filename This will make curl load data from the given file (including any newlines), URL-encode that data and pass it on in the POST. The name part gets an equal sign appended, resulting in name=urlencoded-file-content. Note that the name is expected to be URL-encoded already.

share|improve this answer
Ah, perfect, thank you! – Cornstalks Jan 30 '13 at 3:40

I'll leave qmega's answer as the accepted one, but I'll put an answer I left in a comment here too for easier reading. One other way to do this is simply by specifyping "file=`cat`". For the full command, it would be:

curl --data-urlencode "file=`cat`"
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.