首页 > Web开发 > 详细

js中post格式为base64的数据

时间:2019-09-06 18:20:28      阅读:242      评论:0      收藏:0      [点我收藏+]

参考:https://segmentfault.com/q/1010000000438322

    let url = "https://xxx"
      var httpRequest = new XMLHttpRequest();//第一步:创建需要的对象
      httpRequest.open(POST, url, true); //第二步:打开连接
      httpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");//设置请求头 注:post方式必须设置请求头(在建立连接后设置请求头)
      //发送请求 将情头体写在send中
      httpRequest.send("image=" + encodeURIComponent(base64img))/*获取数据后的处理程序 */
      httpRequest.onreadystatechange = function () {//请求后的回调接口,可将请求成功后要执行的程序写在其中
        if (httpRequest.readyState == 4 && httpRequest.status == 200) {//验证请求是否发送成功
          var json = httpRequest.responseText;//获取到服务端返回的数据
          console.log(json);
        }
      };

 如果不用encodeURIComponent,base64img数据格式总是错误(数据中的等号消失)

js中post格式为base64的数据

原文:https://www.cnblogs.com/cekong/p/11476864.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!