写了一个简单的tornado程序,目的接受脚本post的json数据,解析并response,返回json数据。client脚本如下:#-*-coding:utf-8-*-importurllibimporturllib2importjsonurl='http://127.0.0.1:8888'values={'user':'a','passwd':'b'}jdata=json.dumps(values)req=urllib2.Request(url)req.add_data(jdata)printreq.headersresponse=urllib2.urlopen(req)tornado程序如下:#-*-coding:utf-8-*-importtornado.ioloopimporttornado.webimporttornado.httpserverfromtornado.optionsimportdefine,optionsimportjsondefine("port",default=8888,help='runatest')classMainHandler(tornado.web.RequestHandler):defget(self):info={'user':'leno'}jinfo=json.dumps(info)self.write(jinfo)defpost(self,*args,**kwargs):print'postmessage'printself.request.remote_ipprintself.request.body_argumentsuser=self.get_body_argument('user')pw=self.get_body_argument('passwd')printuserjdata=json.loads(user)printjdatadata=json.loads(jdata)defset_default_headers(self):self.set_header('Content-type','application/json;charset=utf-8')application=tornado.web.Application([(r"/",MainHandler),])if__name__=="__main__":application.listen(8888)tornado.ioloop.IOLoop.instance().start()在get_body_argument处出错:Missingargumentuser,printself.request.body_arguments则显示{'{"passwd":"b","user":"a"}':['']}在client处却正常,请问如何解决?谢谢!
慕姐8265434
扬帆大鱼
相关分类