which encoding should be the file in HTML POST form ?

codethecode

New member
i want to upload a file using python to a web server.i do anything like specifying boundaries and content type but i dont know which encoding to use.here is the upload data.should it be base64 like email attachment or binary ? if binary how its gonna look like ? like this = 010011100101001 ?

req="""POST http://192.168.1.2/bts.cgi HTTP/1.1
Host: 192.168.1.2
Proxy-Connection: keep-alive
Authorization: Basic YWRtaW46YWRtaW4=
Accept: application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.7 (KHTML, like Gecko) Chrome/7.0.517.44 Safari/534.7
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
Content-Type: multipart/form-data; boundary=--AaB03x

--AaB03x
Content-Disposition: form-data; name="redirect"

bt.htm
--AaB03x
Content-Disposition: form-data; name="failure"

fail.htm
--AaB03x
Content-Disposition: form-data; name="type"

file_upload
--AaB03x
Content-Disposition: form-data; name="filename"; filename="1.torrent"
Content-Type: application/octet-stream
Content-Length: """+str(len(str(b64encode(buff2[l1+9:])))+"""
Content-Transfer-Encoding: base64

"""+str(b64encode(buff2[l1+9:]))+"""
--AaB03x
Content-Disposition: form-data; name="B_download"

Upload
--AaB03x--
"""
i did it with base64 but i dont get any response from server after sending. should i specify a content-length in header part whcih shows the total length of the body not only the file part ?
 
Back
Top