예제 #1
0
        public static void Init()
        {
            if (singleton != null)
            {
                return;
            }

            lock ( singletonLock )
            {
                if (singleton != null)
                {
                    return;
                }

                singletonGameObject      = new GameObject();
                singleton                = singletonGameObject.AddComponent <ResponseCallbackDispatcher>();
                singletonGameObject.name = "HTTPResponseCallbackDispatcher";
            }
        }
예제 #2
0
        public static void Init()
        {
            if ( singleton != null )
            {
                return;
            }

            lock( singletonLock )
            {
                if ( singleton != null )
                {
                    return;
                }

                singletonGameObject = new GameObject();
                singleton = singletonGameObject.AddComponent< ResponseCallbackDispatcher >();
                singletonGameObject.name = "HTTPResponseCallbackDispatcher";
            }
        }
예제 #3
0
파일: Request.cs 프로젝트: SonGit/NailGame
        public void Send(Action <Request> callback)
        {
            if (!synchronous && callback != null && ResponseCallbackDispatcher.Singleton == null)
            {
                ResponseCallbackDispatcher.Init();
            }

            completedCallback = callback;

            isDone = false;
            state  = RequestState.Waiting;
            if (acceptGzip)
            {
                SetHeader("Accept-Encoding", "gzip");
            }

            if (this.cookieJar != null)
            {
                List <Cookie> cookies      = this.cookieJar.GetCookies(new CookieAccessInfo(uri.Host, uri.AbsolutePath));
                string        cookieString = this.GetHeader("cookie");
                for (int cookieIndex = 0; cookieIndex < cookies.Count; ++cookieIndex)
                {
                    if (cookieString.Length > 0 && cookieString[cookieString.Length - 1] != ';')
                    {
                        cookieString += ';';
                    }
                    cookieString += cookies[cookieIndex].name + '=' + cookies[cookieIndex].value + ';';
                }
                SetHeader("cookie", cookieString);
            }

            if (bytes != null && bytes.Length > 0 && GetHeader("Content-Length") == "")
            {
                SetHeader("Content-Length", bytes.Length.ToString());
            }

            if (GetHeader("User-Agent") == "")
            {
                SetHeader("User-Agent", "UnityWeb 1.0 ( Unity " + Application.unityVersion + " ) ( " + SystemInfo.operatingSystem + " )");
            }

            if (GetHeader("Connection") == "")
            {
                SetHeader("Connection", "close");
            }

            // Basic Authorization
            if (!String.IsNullOrEmpty(uri.UserInfo))
            {
                SetHeader("Authorization", "Basic " + System.Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(uri.UserInfo)));
            }

            if (synchronous)
            {
                GetResponse();
            }
            else
            {
                ThreadPool.QueueUserWorkItem(new WaitCallback(delegate(object t) {
                    GetResponse();
                }));
            }
        }