使用requests库提交multipart/form-data 格式的请求
Posted Hi,欢迎来到小喜的博客,希望能对你有所帮助!
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用requests库提交multipart/form-data 格式的请求相关的知识,希望对你有一定的参考价值。
前言:
Requests是用Python语言编写,基于urllib,采用Apache2 Licensed开源协议的HTTP库。它比urllib更加方便,可以节约我们大量的工作,完全满足HTTP测试需求。更重要的一点是它支持Python3哦!
一、安装 Requests
>>>pip3 install requests
二、multipart/form-data 格式的请求举例
如下图所示,请求里面有4个参数:handle,option,modify_offer_type,Filedata。其中Filedata需要上传文件。
![技术分享图片](http://upload-images.jianshu.io/upload_images/7116457-7dd1d17a10426a04.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
Request Headers
![技术分享图片](http://upload-images.jianshu.io/upload_images/7116457-565ea967792374e0.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
Request Payload
三、使用requests库提交multipart/form-data 格式的请求
设置cookie
![技术分享图片](http://upload-images.jianshu.io/upload_images/7116457-1a7e783a24908c57.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
提交请求
![技术分享图片](http://upload-images.jianshu.io/upload_images/7116457-4167e8cd57c77f09.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
case数据-yaml
![技术分享图片](http://upload-images.jianshu.io/upload_images/7116457-064673764eeecfa6.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
执行case
如上,希望对你有所帮助~~
图片不清楚的话,请关注同篇文章:http://www.jianshu.com/p/086664a7a12f
以上是关于使用requests库提交multipart/form-data 格式的请求的主要内容,如果未能解决你的问题,请参考以下文章
Requests库入门——应用实例-百度360搜索关键词提交