예제 #1
0
        /// <summary>
        /// IEnumeratable HTTP POST to URI.
        /// </summary>
        /// <returns>Enumeratable Function</returns>
        /// <param name="URI">The Target URI.</param>
        /// <param name="contentType">The Content-Type Header</param>
        /// <param name="payload">The data to be posted.</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 PostReturnedText(string URI, string contentType, string payload, string cookie, System.Action <int, Dictionary <string, string>, string> callback)
        {
            // Assign Busy Flag
            _busy = true;

            // Message Data
            byte[] postData = System.Text.Encoding.ASCII.GetBytes(payload.ToCharArray());

            // Process Headers
            var headers = new Dictionary <string, string> ();

            //headers.Add ("Content-Type", contentType);
            //headers.Add ("Content-Length", postData.Length);
            //if (cookie != null)
            //		headers.Add ("Cookie", cookie);

            var newCall = new WWW(URI, postData, headers);

            yield return(newCall);

            while (!newCall.isDone)
            {
                yield return(new WaitForSeconds(0.01f));
            }

            if (callback != null)
            {
                if (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);
        }
예제 #2
0
        /// <summary>
        /// IEnumeratable HTTP GET Request to URI.
        /// </summary>
        /// <returns>Enumeratable Function</returns>
        /// <param name="URI">The Target URI.</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 GetReturnedText(string URI, string cookie, System.Action <int, Dictionary <string, string>, string> callback)
        {
            // Assign Busy Flag
            _busy = true;

            // Process Headers
            var headers = new Dictionary <string, string> ();

            if (cookie != null)
            {
                headers.Add("Cookie", cookie);
            }

            // Make the call
            var newCall = new WWW(URI, null, headers);

            yield return(newCall);

            while (!newCall.isDone)
            {
                yield return(new WaitForSeconds(0.01f));
            }

            // Callback! (Avoid Unity Bitching)
            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);
        }
예제 #3
0
        /// <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);
        }