WebServer_简单例子
#-*-coding:utf-8-*-
importweb
importjson
urls=("/.*","index")
app=web.application(urls,globals())
classindex:
"""
Server:Apache-Coyote/1.1
Pragram:no-cache
Cache-Control:no-cache,no-store,max-age=0
Expires:Thu,01Jan197000:00:00GMT
Content-Type:application/json;charset=UTF-8
Content-Language:zh-CN
Transfer-Encoding:chunked
"""
defGET(self):
res='你好中国'
#a=res.decode('utf8')
#b=a.encode('gb2312')
web.header('content-type','application/json;chartset=UTF-8')
returnres
defPOST(self):
web.header('content-type','application/json;chartset=UTF-8')
web.header('Server','Webpy')
web.header('Content-Language','zh-CN')
web.header('Pragram','no-cache')
web.header('Cache-Control','no-cache,no-store,max-age=0')
#res={
#"code":0,
#"msg":"success",
#"data":{"table":[{"id":"1","name":"世界上最美的花","fileUrl":"/home/STE-test/Testdata/世界上最美的花.mp3"},
#{"id":"5","name":"夏洛特烦恼","fileUrl":"/home/STE-test/Testdata/夏洛特烦恼.mp3"}
#]
#}
#}
res={"code":0,"msg":"success","data":{"isPlay":1,"duration":3589,"totalTime":3600}}
j_res=json.dumps(res)
returnj_res
if__name__=="__main__":
app.run()