钉钉小程序post提交json,报400、415
下午又可以愉快的写代码了。被这个小问题折磨两天了。其实原因很简单就是提交的json格式不正确。
贴出来正确的代码:
let domain ="http://cquni.vaiwan.com:8771/api/ECard"; let api_url=domain+'/workscan'; let app=getApp(); Page({ data:{ src:'' }, onLoad(){ dd.scan({ type: 'qr', success: (res) => { const code_obj=res.code; if (code_obj.indexOf("{")==-1){ dd.alert({content:'二维码格式不符!'+'\r\n'+'['+code_obj+']'}); return; } //console.log(api_url+'?userId='+app.globalData.current_user); //dd.alert({content:'二维码的内容:'+'\r\n'+'['+code_obj+']'}); const header = {'Content-Type': 'application/json'}; let json_data =JSON.stringify({'userId':app.globalData.current_user,'barcode':code_obj}); dd.httpRequest({ url: api_url, method: 'POST', data:json_data, headers: header, dataType: 'json', success: function(info) { dd.alert({content:JSON.stringify(info)}); }, fail: function(res) { dd.alert({content:'网络故障!'+'\r\n'+JSON.stringify(res)}); } }); }, }); }, })
作者:数据酷软件
出处:https://www.cnblogs.com/datacool/p/12509595.html
关于作者:20年编程从业经验,持续关注MES/ERP/POS/WMS/工业自动化
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明。
联系方式: qq:71008973;wx:6857740733
基于人脸识别的考勤系统 地址: https://gitee.com/afeng124/viewface_attendance_ext
自己开发安卓应用框架 地址: https://gitee.com/afeng124/android-app-frame
WPOS(warehouse+pos) 后台演示地址: http://47.239.106.75:8080/