标签:
egret的文档还不错,不过http请求参数的文档居然没有,于是自己摸索了一下,
发现原来是直接传字符串参数就可以了。于是封装了一个类,方便使用。
class RequestParam { public data = {}; public toString(): string { var res = ""; for (var key in this.data) { if(res==""){ res += key + "=" + this.data[key]; }else{ res += "&" + key + "=" + this.data[key]; } } return res; } }
用法:
var param = new RequestParam();
param.data["aa"] = 123;
param.data["bb"] = "aa";
var request = new egret.HttpRequest();
request.send(param.toString());
如果是post请求则需要设置请求头,
request.setRequestHeader(‘Content-Type‘, ‘application/x-www-form-urlencoded; charset=UTF-8‘);
标签:
原文地址:http://www.cnblogs.com/xdao/p/egret_requestparam.html