<div>Thanks, thats a big help!</div> <div> </div> <div>only two things I don't understand well. when I create a http object with HTTPConnection() do I want this to be to my web host server (hostway.com) or to the server I'm posting to (authorize.net)?</div> <div> </div> <div>and what are the headers used for?</div> <div> </div> <div>again, thanks!</div> <div> </div> <div>Jeff<BR><BR><B><I>Graham Dumpleton <graham.dumpleton@gmail.com></I></B> wrote:</div> <BLOCKQUOTE class=replbq style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #1010ff 2px solid">On 05/11/2007, Alex Botero-Lowry <ALEX@PUDDLEJUMPER.FOXYBANANA.COM>wrote:<BR>> On Sun, Nov 04, 2007 at 05:14:31PM -0800, Jeff Peery wrote:<BR>> > hello,<BR>> > I'm pretty new to using python on the web, I've got a bit of code<BR>> > that works pretty well to get form inputs and such. Now I need to post<BR>> > some info to a gateway service (for credit card
processing) and then<BR>> > receive their response and do something with it. I can do this no<BR>> > problem... except that I'm not sure how to post my dictionary (name<BR>> > value pairs from form inputs i.e., credit card num, expire dates etc)<BR>> > from the cgi script. I had been using the html forms to submit data to<BR>> > the server, but now I need to do this from my cgi script. I think this is<BR>> > pretty straight forward but I didn't see anything in the cgi module.<BR>> > where do I start, or does anyone have some sample code? thanks!!<BR>><BR>> You'll need httplib which luckily come with the stdlib so no need to install<BR>> anything.<BR>><BR>> Something like this should get you going:<BR>><BR>> conn = httplib.HTTPConnection(remote_server)<BR>> values = '&'.join([ '%s=%s' % a for a in values.items() ])<BR><BR>From memory, better off using urllib.urlencode() for this as it will<BR>properly
quote and convert special characters.<BR><BR>> headers={'Content-Type':'application/x-www-form-urlencoded'}<BR>> conn.request(method, url, values, headers=headers)<BR>> res = conn.getresponse()<BR>> data = res.read()<BR>> return (res.status, res.reason, output)<BR>><BR>> the important bits here are our crappy makeshift<BR>> application/x-www-form-urlencoded rncoder which<BR>> is the values line and our setting of the content-type. We also<BR>> need to make sure the method passed to conn.request is 'POST' or<BR>> 'PUT' (almost certainly POST) as these are the only ones that accept<BR>> a body. I think the cgi module may have a better way of doing the<BR>> encoding, but i've never found it.<BR>><BR>> Alex<BR>> _______________________________________________<BR>> Web-SIG mailing list<BR>> Web-SIG@python.org<BR>> Web SIG: http://www.python.org/sigs/web-sig<BR>> Unsubscribe:
http://mail.python.org/mailman/options/web-sig/graham.dumpleton%40gmail.com<BR>><BR></BLOCKQUOTE><BR><p> __________________________________________________<br>Do You Yahoo!?<br>Tired of spam? Yahoo! Mail has the best spam protection around <br>http://mail.yahoo.com