12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- using LitJson;
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- public class URLRequestData
- {
- private bool encrypt;
- private List<KeyValuePair<string, object>> data;
- public URLRequestData(bool encrypt=false)
- {
- this.encrypt = encrypt;
- data = new List<KeyValuePair<string, object>>();
- }
- public void Add(string key, object value)
- {
- data.Add(new KeyValuePair<string, object>(key, value));
- }
- public bool HasData()
- {
- return data.Count > 0;
- }
- public string GetDataString()
- {
- string info = "";
- string result = "";
- if(encrypt)
- {
- JsonData json = JsonMapper.ToObject("{}");
- for(int i=0; i<data.Count; i++)
- {
- KeyValuePair<string, object> 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<data.Count; i++)
- {
- KeyValuePair<string, object> 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<data.Count; i++)
- {
- KeyValuePair<string, object> 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<data.Count; i++)
- {
- KeyValuePair<string, object> kvp = data[i];
- info += "["+kvp.Key+" : "+kvp.Value+"] ";
-
- form.AddField(kvp.Key, kvp.Value.ToString());
- }
- }
- Debuger.Log("Url data : "+info);
- return form;
- }
- }
|