Make it Better
Unity弱联网 HTTP post,get弱联网写法
2016-10-7 StanWind
public void getRankD(){
Dictionary<string,string> data = new Dictionary<string,string>();
data.Add ("command", "Ranking_Order_Access");
data.Add ("sessionKey", "FA9A4172E6F91F4897829B6AA762811E");
data.Add ("imei", GMUTILS.getIMEI());
data.Add ("game_id", "8");
data.Add ("type", "1");
data.Add ("order_type", "2");
data.Add ("order_value", "2-4");

StartCoroutine (POST(MAINURL,data));
}

IEnumerator POST(string url,Dictionary<string,string> data){
//1.新建一张提交表单
WWWForm dataForm = new WWWForm ();
//2.装载数据
foreach (KeyValuePair<string,string >postParams in data) {
Debug.Log (postParams.Key);
dataForm.AddField (postParams.Key, postParams.Value);
}

//3.创建POST实体
www = new WWW (url, dataForm);

yield return www;

mProgress = www.progress;
if (www.error != null) {
mContent = www.error;
} else {
mContent = www.text;
}

Debug.Log (mContent);

Debug.Log ("session---->"+ GMUTILS.getValueByKey (mContent, "sessionKey"));
}

IEnumerator GET(string url){
www = new WWW (url);
yield return www;

mProgress = www.progress;
if (www.error != null) {
mContent = www.error;
Debug.Log ("Error");
} else {
mContent = www.text;
}
}
发表评论:
昵称

邮件地址 (选填)

个人主页 (选填)

内容