Dear All
I'm trying to send a file to Webwares FileUpload.py in the examples. But I'm
not able to make this work. I tried to capture what the browser sends to the
server. I need this for some automation tasks.
I'm using Apache 1.3.23 and Webware7b1
Suppose I have c:/web.txt...
-----------------------------7d21b62f5011e
Content-Disposition: form-data; name="filename"; filename="C:\kk.txt"
Content-Type: text/plain
Only testing
-----------------------------7d21b62f5011e
Content-Disposition: form-data; name="_action_"
fileupload
-----------------------------7d21b62f5011e--
...so my upload code is something like:
# send form with file data test
file='c:/web.txt'
f=open(file)
boundary=f.readline()[:-1] # read the boundary
data="%s\n%s" % (boundary, f.read()) #all data
f.close()
host='127.0.0.1'
import httplib,urllib
h=httplib.HTTP(host)
h.putrequest('POST','/WK/FileUpload')
h.putheader('Content-type','multipart/form-data; boundary=%s' % boundary)
h.putheader('Content-Length',`len(data)`)
h.putheader('Accept', '*/*')
h.endheaders()
h.send(data)
reply,msg,hdrs=h.getreply()
print "reply: %s" % reply
f=h.getfile()
res=f.read()
f.close()
print "result: %s" % res
print "hdrs: %s"% hdrs
I never get the 'You sent the following data: ....' response from the page.
Could anyone give me another example on how to upload data to a form, or see
what POST variables do I have?
Thanx, Erny
|