def do_POST(self):
# http://stackoverflow.com/questions/4233218/python-basehttprequesthandler-post-variables
ctype, pdict = cgi.parse_header(self.headers['content-type'])
if ctype == 'multipart/form-data':
postvars = cgi.parse_multipart(self.rfile, pdict)
elif ctype == 'application/x-www-form-urlencoded':
length = int(self.headers['content-length'])
postvars = cgi.parse_qs(self.rfile.read(length), keep_blank_values=1)
else:
postvars = {}
# print(postvars)
if 'Username' not in list(postvars.keys()) \
or 'Password' not in list(postvars.keys()):
log('E', 'vali.', 'No credentials.')
self.exit_on_error('No credentials.')
return
if not validate_id(postvars['Username'][0], postvars['Password'][0]):
log('E', 'vali.', 'Wrong credentials.')
self.exit_on_error('Wrong credentials.')
return
# print(postvars)
try:
dispatch(postvars)
self.write_response({'Status': 'OK'})
except:
log('E', 'hand.', 'Handler throws an exception.')
self.exit_on_error('Handler throws and exception.')
评论列表
文章目录