Is it possible to change Content-type?

John J. Lee jjl at
Sat Jun 14 17:06:26 CEST 2003

"A" <printers at> writes:

>  Suppose we have the following form:
>  <FORM action=""
>        enctype="multipart/form-data"
>        method="post">
>  </FORM>>
> If the user enters "Larry" in the text input, and selects the text
> file "file1.txt", the user agent might send back the following data:
>    Content-Type: multipart/form-data; boundary=AaB03x
> Is it possible to simulate the behaviour of the user agent and
> use 

Have you actually checked to see what your user agent (aka web
browser, I assume) sends?

> Content-type: application/x-www-form-urlencoded
> and send the data as 
> submit-name=Larry&files"; filename="file1.txt" Content-Type: 
> text/plain

Neither RFC 1867 (see also RFC 1866) and HTML 4.01 say you *have* to
do file upload using multipart/form-data, but the server might not
like it if you use application/x-www-form-urlencoded.  In fact, I
think if you go by the letter of HTML 4.01, you'd send back 'files='
for your file control (or possibly nothing at all) if you're using
x-www-form-urlencoded, which isn't very much use.  'files=Larry' might
possibly work, but I don't see why you'd want to try, really.

In other words, don't do that.

RFC 2388 is also relevant to multipart/form-data.

The 0.1.2a version of the following might help you (ATM, I've only
tested the file upload code against the cgi module, and it only does
single-file upload -- and IIRC it would just send 'files=' if you
explicitly asked for form.enctype = "application/x-www-form-urlencoded").


More information about the Python-list mailing list