Parse http GET and POST parameters from BaseHTTPHandler?

前端 未结 5 1311
春和景丽
春和景丽 2020-12-08 07:10

BaseHTTPHandler from the BaseHTTPServer module doesn\'t seem to provide any convenient way to access http request parameters. What is the best way to parse the GET paramete

5条回答
  •  感动是毒
    2020-12-08 07:25

    You may want to use urllib.parse:

    >>> from urllib.parse import urlparse, parse_qs
    >>> url = 'http://example.com/?foo=bar&one=1'
    >>> parse_qs(urlparse(url).query)
    {'foo': ['bar'], 'one': ['1']}
    

    For Python 2, the module is named urlparse instead of url.parse.

提交回复
热议问题