python hack-requests_requests使用multipart/formdata提交post请求的hack姿势

from pprint import pprint

import requests

URL = 'http://httpbin.org/post'

DATA = {'title': 'title', 'content': 'content'}

HEADERS = {'content-type': 'multipart/form-data; boundary={0}'.format('test')}

def post_data():

resp = requests.post(URL, data=DATA)

pprint(resp.json())

def post_with_formdata_header():

resp = requests.post(URL, headers=HEADERS, data=DATA)

pprint(resp.json())

def post_use_files_for_hack():

resp = requests.post(URL, files=DATA)

pprint(resp.json())

def post_data_but_empty_files():

resp = requests.post(URL, data=DATA, files={})

pprint(resp.json())

def post_data_and_files():

resp = requests.post(URL, data=DATA, files={'files': 'hack'})

pprint(resp.json())

post_data()

# {u'args': {},

# u'data': u'',

# u'files': {},

# u'form': {u'content': u'content', u'title': u'title'},

# u'headers': {u'Accept': u'*/*',

# u'Accept-Encoding': u'gzip, deflate',

# u'Cache-Control': u'max-age=259200',

# u'Content-Length': u'27',

# u'Content-Type': u'application/x-www-form-urlencoded',

# u'Host': u'httpbin.org',

# u'User-Agent': u'python-requests/2.11.1'},

# u'json': None,

# u'origin': u'103.7.28.136',

# u'url': u'http://httpbin.org/post'}

post_with_formdata_header()

# {u'args': {},

# u'data': u'',

# u'files': {},

# u'form': {},

# u'headers': {u'Accept': u'*/*',

# u'Accept-Encoding': u'gzip, deflate',

# u'Cache-Control': u'max-age=259200',

# u'Content-Length': u'23',

# u'Content-Type': u'multipart/form-data; boundary=test',

# u'Host': u'httpbin.org',

# u'User-Agent': u'python-requests/2.11.1'},

# u'json': None,

# u'origin': u'103.7.28.136',

# u'url': u'http://httpbin.org/post'}

post_use_files_for_hack()

# {u'args': {},

# u'data': u'',

# u'files': {u'content': u'content', u'title': u'title'},

# u'form': {},

# u'headers': {u'Accept': u'*/*',

# u'Accept-Encoding': u'gzip, deflate',

# u'Cache-Control': u'max-age=259200',

# u'Content-Length': u'262',

# u'Content-Type': u'multipart/form-data; boundary=28d6573b04524ce38c500e92e53d2145',

# u'Host': u'httpbin.org',

# u'User-Agent': u'python-requests/2.11.1'},

# u'json': None,

# u'origin': u'103.7.28.136',

# u'url': u'http://httpbin.org/post'}

post_data_but_empty_files()

# {u'args': {},

# u'data': u'',

# u'files': {},

# u'form': {u'content': u'content', u'title': u'title'},

# u'headers': {u'Accept': u'*/*',

# u'Accept-Encoding': u'gzip, deflate',

# u'Cache-Control': u'max-age=259200',

# u'Content-Length': u'27',

# u'Content-Type': u'application/x-www-form-urlencoded',

# u'Host': u'httpbin.org',

# u'User-Agent': u'python-requests/2.11.1'},

# u'json': None,

# u'origin': u'103.7.28.136',

# u'url': u'http://httpbin.org/post'}

post_data_and_files()

# {u'args': {},

# u'data': u'',

# u'files': {u'files': u'hack'},

# u'form': {u'content': u'content', u'title': u'title'},

# u'headers': {u'Accept': u'*/*',

# u'Accept-Encoding': u'gzip, deflate',

# u'Cache-Control': u'max-age=259200',

# u'Content-Length': u'332',

# u'Content-Type': u'multipart/form-data; boundary=0f46e83f5f90440288b820a72a8eeb17',

# u'Host': u'httpbin.org',

# u'User-Agent': u'python-requests/2.11.1'},

# u'json': None,

# u'origin': u'103.7.28.136',

# u'url': u'http://httpbin.org/post'}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值