- 参考链接:https://www.cnblogs.com/yhleng/p/10696922.html
我的代码
#!/usr/bin/python3.x
# -*- coding: utf-8 -*-
# @Time : 2021/5/17 16:37
# @Author : hike
# @Email : @gmail.com
# @File : post2.py
# @Software: PyCharm
# multipart/form-data
class MultipartFormData(object):
"""multipart/form-data格式转化"""
@staticmethod
def format(data, boundary="----WebKitFormBoundary7MA4YWxkTrZu0gW", headers={
}):
"""
form data
:param: data: {"req":{"cno":"18990876","flag":"Y"}}
:param: boundary: "----WebKitFormBoundary7MA4YWxkTrZu0gW"
:param: headers: 包含boundary的头信息;如果boundary与headers同时存在以headers为准
:return: str
:rtype: str
"""
# 从headers中提取boundary信息
if "content-type" in headers:
fd_val = str(headers["content-type"])
if "boundary" in fd_val:
fd_val = fd_val.split(";")[1].strip()
boundary = fd_val.split(