Python requests.post方法中data与json

2017-09-25  本文已影响0人  Sunnky

requests.post()方法
源码如下:

def post(url, data=None, json=None, **kwargs):
    r"""Sends a POST request.

    :param url: URL for the new :class:`Request` object.
    :param data: (optional) Dictionary (will be form-encoded), bytes, or file-like object to send in the body of the :class:`Request`.
    :param json: (optional) json data to send in the body of the :class:`Request`.
    :param \*\*kwargs: Optional arguments that ``request`` takes.
    :return: :class:`Response <Response>` object
    :rtype: requests.Response
    """

    return request('post', url, data=data, json=json, **kwargs)

可以看到,参数中明确的参数有datajson
datajson既可以是str,也可以是dict
区别如下:

content-type=application/json下,获取值的方法如下:

json.loads(request.body.decode())
上一篇下一篇

猜你喜欢

热点阅读