Beispiel #1
0
 public virtual void Send(Action <Request> callback = null)
 {
     if (!synchronous && callback != null && ResponseCallbackDispatcher.Singleton == null)
     {
         ResponseCallbackDispatcher.Init();
     }
     completedCallback = callback;
     isDone            = false;
     state             = RequestState.Waiting;
     if (acceptGzip)
     {
         SetHeader("Accept-Encoding", "gzip");
     }
     if (cookieJar != null)
     {
         List <Cookie> cookies = cookieJar.GetCookies(new CookieAccessInfo(uri.Host, uri.AbsolutePath));
         string        text    = GetHeader("cookie");
         for (int i = 0; i < cookies.Count; i++)
         {
             if (text.Length > 0 && text[text.Length - 1] != ';')
             {
                 text += ';';
             }
             object obj = text;
             text = string.Concat(obj, cookies[i].name, '=', cookies[i].value, ';');
         }
         SetHeader("cookie", text);
     }
     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 4.6 ) ( Mac OS X 10.9 )");
     }
     if (GetHeader("Connection") == "")
     {
         SetHeader("Connection", "close");
     }
     if (!string.IsNullOrEmpty(uri.UserInfo))
     {
         SetHeader("Authorization", "Basic " + Convert.ToBase64String(Encoding.ASCII.GetBytes(uri.UserInfo)));
     }
     if (synchronous)
     {
         GetResponse();
         return;
     }
     ThreadPool.QueueUserWorkItem(delegate
     {
         GetResponse();
     });
 }
Beispiel #2
0
 public static void Init()
 {
     if (singleton != null)
     {
         return;
     }
     lock (singletonLock)
     {
         if (!(singleton != null))
         {
             singletonGameObject      = new GameObject();
             singleton                = singletonGameObject.AddComponent <ResponseCallbackDispatcher>();
             singletonGameObject.name = "HTTPResponseCallbackDispatcher";
         }
     }
 }
        public static void Init()
        {
            if ( singleton != null )
            {
                return;
            }

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

                singletonGameObject = new GameObject();
                singleton = singletonGameObject.AddComponent< ResponseCallbackDispatcher >();
                singletonGameObject.name = "HTTPResponseCallbackDispatcher";
            }
        }
Beispiel #4
0
        public virtual void Send(Action <HTTP.Request> callback = null)
        {
            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 (byteStream != null && byteStream.Length > 0 && GetHeader("Content-Length") == "")
            {
                SetHeader("Content-Length", byteStream.Length.ToString());
            }

            if (GetHeader("User-Agent") == "")
            {
                try {
                    SetHeader("User-Agent", "UnityWeb/1.0 (Unity " + Request.unityVersion + "; " + Request.operatingSystem + ")");
                } catch (Exception) {
                    SetHeader("User-Agent", "UnityWeb/1.0");
                }
            }

            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();
                }));
            }
        }