/// <summary> /// Form the specified URI, formStringData, formBinaryData, cookie and callback. /// </summary> /// <returns>The Call Hash</returns> /// <param name="URI">The Target URI</param> /// <param name="formStringData">A Dictionary<string,string> of Form Data</param> /// <param name="formBinaryData">A custom binary dataset. Useful for uploading pictures.</param> /// <param name="cookie">Any previous cookie data to be used for authentication.</param> /// <param name="callback">A callback function (int hash, Hashtable headers, string payload).</param> public int Form(string URI, Dictionary<string,string> formStringData, WebPool.FormBinaryData[] formBinaryData, string cookie, System.Action<int, Dictionary<string,string>, string> callback) { _hash = (Time.time + URI + formStringData.GetHashCode () + UnityEngine.Random.Range (0, 100)).GetHashCode (); StartCoroutine (FormReturnedText (URI, formStringData, formBinaryData, cookie, callback)); return _hash; }
/// <summary> /// IEnumeratable HTTP POST Form to URI. /// </summary> /// <returns>IEnumeratable Function</returns> /// <param name="URI">The Target URI.</param> /// <param name="formStringData">A Dictionary<string,string> of Form Data</param> /// <param name="formBinaryData">A custom binary dataset. Useful for uploading pictures.</param> /// <param name="cookie">Any previous cookie data to be used for authentication.</param> /// <param name="callback">A callback function (int hash, Hashtable headers, string payload).</param> IEnumerator FormReturnedText(string URI, Dictionary<string, string> formStringData, WebPool.FormBinaryData[] formBinaryData, string cookie, System.Action<int, Dictionary<string,string>, string> callback) { // Assign Busy Flag _busy = true; var newForm = new WWWForm (); // Add string data if (formStringData != null) { foreach (string s in formStringData.Keys) { newForm.AddField (s, formStringData [s]); } } // Add binary data if (formBinaryData != null) { foreach (WebPool.FormBinaryData b in formBinaryData) { newForm.AddBinaryData (b.FieldName, b.Data, b.FileName, b.MimeType); } } var headers = new Dictionary<string, string> (); foreach (KeyValuePair<string, string> entry in newForm.headers) { headers.Add (entry.Key, entry.Value); } if (cookie != null) headers.Add ("Cookie", cookie); var newCall = new WWW (URI, newForm.data, headers); yield return newCall; while (!newCall.isDone) yield return new WaitForSeconds (0.01f); // Callback! if (callback != null) { if (newCall.responseHeaders.ContainsKey ("STATUS") && newCall.responseHeaders ["STATUS"].Contains (" 200 ")) callback (_hash, new Dictionary<string,string> (newCall.responseHeaders), newCall.text); else callback (_hash, new Dictionary<string,string> (newCall.responseHeaders), ""); } _busy = false; ParentPool.Despawn (gameObject); }