zoukankan      html  css  js  c++  java
  • html复杂url提交

    在使用手机向webapi发送照片请求的时候遇到一个问题,关于base64位字符串码无法识别,提交的表单是这样的:

    <form id="form1" method="post" action="http://localhost:10322/food/Buy?date='2015-2-12'&content=balabala内容">
    <div>
    <input type="text" name="PhotoInfo" value="base位码"/>
    <input type="submit" value="提交" />
    </div>
    </form>

    由于PhotoInfo特别长,不能放在url拼接,会报异常,所以放在form里面提交,但是api端却捕捉不到,产生url异常.

    解决方案:在对应的buy方法的PhotoInfo参数前面加上[Frombody]标记

    public ResponseMessage Buy(string date,string content,[FromBody] string PhotoInfo)

    加上这个标记后,webapi端能找到了,但是又有问题出现了,photoInfo明明有值,传进来却是null,查了一下,默认string类型不会传值,必须用自定义类型,好吧,定义个自定义类型

    public class Photo {
            public string Extension { get; set; }
            public string PhotoImage { get; set; }
        }

    然后在参数使用的地方改成

    public ResponseMessage Buy(string date,string content,[FromBody] Photo PhotoInfo)

    取值的地时候要用PhotoInfo.PhotoImage,这时候就有值了,另外,在传base64位码的时候,前面的data:image/gif;base64, 这个不能加上,加上识别不了。

  • 相关阅读:
    ubuntu16.04本地软件源搭建
    2080TI显卡ubuntu16.04机器学习安装和克隆
    PLSQL导入excel数据方法
    只有英伟达显卡输出口的电脑安装ubuntu系统记录
    百度人脸识别学习
    http application/x-www-form-urlencoded 模式响应学习
    JS中继承的几种实现方式
    浅拷贝和深拷贝
    防抖和节流
    HTML知识点总结
  • 原文地址:https://www.cnblogs.com/sky2014/p/4287574.html
Copyright © 2011-2022 走看看