django里post请求问题

class Base(object):
    def postData(self, res):
        '''
        这是根据查看django里的request.post源码发现的
        这里请求发数据发送给django后用request.post请求的话请求头需要是
        header: content - type: application / x - www - form - urlencoded才可以接受到.一般会携带在浏览器请求头里
        content-type: application/json,json的格式request.post是接受不到的,只有在request.body才可以获得数据
        '''
        # requests.post(settings.API_URL, data=json.dumps(res))
        # 下面与上面的方式相等,进行了优化简写
        requests.post(settings.API_URL, json=res)

截图django里的request.post源码截图

猜你喜欢

转载自www.cnblogs.com/jutao/p/11099430.html