Python Gunicorn 获取get 或post参数

对于Get请求

import urlparse
def app(env, start_response):
url = env['RAW_URI']
data = ""
if "=" in env['RAW_URI']:
data = urlparse.parse_qs(urlparse.urlsplit(url).query)['name'][0]
start_response("200 OK", [
("Content-Type", "text/plain"),
("Content-Length", str(len(data)))
])
return iter([data])

对于Post请求

import urlparse
def app(env, start_response):
data = env['wsgi.input'].read()
start_response("200 OK", [
("Content-Type", "text/plain"),
("Content-Length", str(len(data)))
])
return iter([data])
赞 (1) 打赏

评论 0

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏