在用 requests模拟提交一个网站的回复时,通过调试面板发现表单提交是 multipart/form-data而非普通的 form表单的 application/x-www-form-urlencoded
格式为
在此卡住了,不知道改如何提交这种格式的
搜索后发现前人的解决办法也并不十分恰当
其它关于multipart/form-data 的只看到了关于文件上传的文章,requests 官方文档也是文件而非表单。
欢迎协助修改问题描述让问题描述更精准而简练
望各位帮忙
来自requests官方文档
http://docs.python-requests.org/en/latest/user/quickstart/#post-a-multipart-encoded-file
url = 'http://httpbin.org/post'
files = {'file': open('report.xls', 'rb')}
r = requests.post(url, files=files)
上面的例子是只传文件的情况
如果在传文件时还传递其他表单信息,可以请求时指定data参数
url = 'http://httpbin.org/post'
files = {'file': open('report.xls', 'rb')} # 文件
datat = {'name':'hqs0417'} # 其他表单
r = requests.post(url, files=files, data=data)
直接postman
你是在说前端么?jquery.form可以用ajax方式提交
设置request-header就好了
你是想提交 application/x-www-form-urlencoded 这样的表单吗?
我想通过魔改请求headers可以实现
requests.post(url, headers={'Content-type': 'application/x-www-form-urlencoded'}, ...)
requests.post(url, files=files, data=data) 这样不就好了
如果是测试的话,装一个chrome插件:postman;如果是代码模拟的话,可以试试html5的FormData