using UnityEngine; using System.Collections; using System.Collections.Generic; using LitJson; public class URLRequestData { private bool encrypt; private List> data; private KeyValuePair file; public URLRequestData(bool encrypt=false) { this.encrypt = encrypt; data = new List>(); file = new KeyValuePair (); } public void Add(string key, object value) { data.Add(new KeyValuePair(key, value)); } public void AddFile(string key, byte[] file) { this.file = new KeyValuePair (key, file); } public bool HasData() { return data.Count > 0 || !StringUtil.Empty(file.Key); } public string GetDataString() { string info = ""; string result = ""; if(encrypt) { JsonData json = JsonMapper.ToObject("{}"); for(int i=0; i kvp = data[i]; info += "["+kvp.Key+" : "+kvp.Value+"] "; json[kvp.Key] = kvp.Value.ToString(); } result = "v="+DecryptionUtil.Encryption(json.ToJson()); } else { string[] strArr = new string[data.Count]; for(int i=0; i kvp = data[i]; info += "["+kvp.Key+" : "+kvp.Value+"] "; strArr[i] = kvp.Key+"="+kvp.Value; } result = string.Join("&", strArr); } Debuger.Log("Url data : "+info); return result; } public WWWForm GetDataForm() { string info = ""; WWWForm form = new WWWForm(); if(encrypt) { JsonData json = JsonMapper.ToObject("{}"); for(int i=0; i kvp = data[i]; info += "["+kvp.Key+" : "+kvp.Value+"] "; json[kvp.Key] = kvp.Value.ToString(); } form.AddField("v", DecryptionUtil.Encryption(json.ToJson())); } else { for(int i=0; i kvp = data[i]; info += "["+kvp.Key+" : "+kvp.Value+"] "; form.AddField(kvp.Key, kvp.Value.ToString()); } } if(!StringUtil.Empty(file.Key)) { form.AddBinaryData (file.Key, file.Value); info += "[" + file.Key + " : bytes " + file.Value.Length + "]"; } Debuger.Log("Url data : "+info); return form; } }