'content-type': 'application/x-www-form-urlencoded; charset=UTF-8'
当使用表单方式提交的时候,无法像浏览器一样传输数组。希望尽快修复。
wx.request({ url: xxx, //仅为示例,并非真实的接口地址 data: { "rs": "login", "rsargs": [ 'aaa',1 ] }, method: "POST", header: { 'content-type': 'application/x-www-form-urlencoded' }, success: function (res) { }}) |
请求的格式是下面这样的
正常浏览器是这样的

估计你和我遇到的问题是一样的。
解决方法,使用jquery的param方法 包装参数就好了
1. header配置为 x-www-formxxxxx....
2. 包装参数
reqData = this._param(reqData);其中 _param 就是 jquery的$.param方法 copy过来就好。
_param:function(a, traditional) {varclass2type = {};vartoString = class2type.toString;varhasOwn = class2type.hasOwnProperty;functiontoType(obj) {if(obj ==null) {returnobj +"";}// Support: Android <=2.3 only (functionish RegExp)returntypeofobj ==="object"||typeofobj ==="function"?class2type[toString.call(obj)] ||"object":typeofobj;}varisFunction =functionisFunction(obj) {// Support: Chrome <=57, Firefox <=52// In some browsers, typeof returns "function" for HTML <object> elements// (i.e., `typeof document.createElement( "object" ) === "function"`).// We don't want to classify *any* DOM node as a function.returntypeofobj ==="function"&&typeofobj.nodeType !=="number";};varrbracket = /\[\]$/,rCRLF = /\r?\n/g,rsubmitterTypes = /^(?:submit|button|image|reset|file)$/i,rsubmittable = /^(?:input|select|textarea|keygen)/i;functionbuildParams(prefix, obj, traditional, add) {varname;if(Array.isArray(obj)) {// Serialize array item.obj.forEach(function(v, i) {if(traditional || rbracket.test(prefix)) {// Treat each array item as a scalar.add(prefix, v);}else{// Item is non-scalar (array or object), encode its numeric index.buildParams(prefix +"["+ (typeofv ==="object"&& v !=null? i :"") +"]",v,traditional,add);}});}elseif(!traditional && toType(obj) ==="object") {// Serialize object item.for(nameinobj) {buildParams(prefix +"["+ name +"]", obj[name], traditional, add);}}else{// Serialize scalar item.add(prefix, obj);}}// Serialize an array of form elements or a set of// key/values into a query stringvarparam =function(a, traditional) {varprefix,s = [],add =function(key, valueOrFunction) {// If value is a function, invoke it and use its return valuevarvalue = isFunction(valueOrFunction) ?valueOrFunction() :valueOrFunction;s[s.length] = encodeURIComponent(key) +"="+encodeURIComponent(value ==null?"": value);};// If an array was passed in, assume that it is an array of form elements.if(Array.isArray(a)) {// Serialize the form elementsa.forEach(function(item) {add(item.name, item.value);});}else{// If traditional, encode the "old" way (the way 1.3.2 or older// did it), otherwise encode params recursively.for(prefixina) {buildParams(prefix, a[prefix], traditional, add);}}// Return the resulting serializationreturns.join("&");};returnparam(a, traditional);},偷个懒 直接copy粘贴过来 试试吧,我这边测试没有问题
把数组用 JSON.stringify转化成字符串吧