File upload using httplib
Peter Hansen
peter at engcorp.com
Mon Jul 26 09:24:20 EDT 2004
alastair wrote:
> I'm attempting to test out some functionality of the Apache http
> server.
> I'm no expert when it comes to the http standard so I'm not sure if
> using httplib is the right way to go about things. If anyone has any
> advice on how to go about this, I'd appreciate it.
What you are doing is mostly fine. Why not try it at the
interactive interpreter prompt and experiment for yourself?
This is Python: there's no excuse for not playing. :-)
> import httplib, urllib
>
> params = urllib.urlencode({'spam': 1, 'eggs': 2})
>
> headers = {"Content-type": "application/x-www-form-urlencoded",
> "Accept": "text/plain"}
>
> conn = httplib.HTTPConnection("127.0.0.1:8080")
> conn.request("POST", "/test/test.py")
You don't use "headers" anywhere... note it should be a parameter
to conn.request().
At this point, though, you haven't really asked a question,
and your code should mostly work (barring syntax errors etc,
as I haven't tried it myself). Why not try it out and post
questions if you have trouble and can't solve it yourself?
-Peter
More information about the Python-list
mailing list