zoukankan      html  css  js  c++  java
  • python代码- post请求图片上传

    postman中 的一个请求接口,post请求

     请求特点:其他请求参数均正常,text类型,只有file字段是file类型

    捕捉了一下,

     这样的post请求,用headers为 Content-Type 用Application/Json 或 Application/x-www-form-urlencoded,这两种常用 json或form,python post请求。均无法请求成功,返回500错误。

     请求 抓包,headers 中 的Content-Type:multipart/form-data 注释,只要上面那个

    解决方法如上。 python 中代码:

    url = '%s:18080/oss/file/upload' % url
    files = {'file':('front.png',open('C:/Users/fang/front.png','rb'),'image/png')}
    headers = {'Postman-Token':'fbb65c0f-ce30-4183-9ee3-616c535a9977'}
    data = originmessage.youzanOSSUPLoad.copy() # data 是个dict data中字段比较多,一起upLoad中
    re = requests.post(url,headers=headers,data=data,files=files)
    print(re.text,re.json())

    file图片文件,直接发送files参数。其他字段发送data参数即可

    关键点:headers 中 content-type 一定要删除, 只发送 token 相关即可。

    写这个请求的时候,查了资料,与正常请求方式麻烦点,记录下

  • 相关阅读:
    页面跳转刷新
    表格表头绘制对角线(不固定表格宽高)
    发送邮件的工具类
    重写equals()和hashCode()
    设计模式--原型模式[转载]
    设计模式--外观模式
    设计模式--代理模式
    js处理json js递归
    MySQL锁详解
    开发一个微信小程序实例教程
  • 原文地址:https://www.cnblogs.com/MTXue/p/13920078.html
Copyright © 2011-2022 走看看