Esempio n. 1
0
 protected void InvokeCallback()
 {
     if (m_Callback != null)
     {
         m_Callback(this);
     }
     m_Callback = null;
 }
Esempio n. 2
0
    private static void Init(string url, Hashtable formData, WWWCallback callback)
    {
        WebRequest request = (new GameObject("[ WEB REQUEST ]")).AddComponent <WebRequest>();

        s_all.Add(request);
        request.m_callback = callback;
        request.url        = url;
        request.m_formData = formData;
    }
Esempio n. 3
0
        public void Post(WWWRequest wwwRequest, WWWCallback callback)
        {
            if (wwwRequest.HasProxy)
            {
                wwwRequest.Parameters[WWWConsts.REQUEST_CONTENT_TYPE_PROXY] = wwwRequest.Init[WWWConsts.REQUEST_CONTENT_TYPE];
                wwwRequest.Init[WWWConsts.REQUEST_CONTENT_TYPE]             = "application/x-www-form-urlencoded";
            }

            WWWForm form = new WWWForm();

            {
                IDictionaryEnumerator enumerator = wwwRequest.AllParameters.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    string key   = enumerator.Key as string;
                    string value = enumerator.Value as string;

                    if (null != key && null != value)
                    {
                        form.AddField(key, value);
                    }
                    else
                    {
                        Logger.LogWarning("Key or value... null: key={0}, value={1}", key, value);
                    }
                }
            }
            Hashtable headers = form.headers;
            {
                IDictionaryEnumerator enumerator = wwwRequest.Init.GetEnumerator();

                while (enumerator.MoveNext())
                {
                    string key   = (enumerator.Key is string) ? enumerator.Key as string : enumerator.Key.ToString();
                    string value = (enumerator.Value != null) ? enumerator.Value.ToString() : null;

                    if (!string.IsNullOrEmpty(key) && !string.IsNullOrEmpty(value))
                    {
                        try {
                            headers[key] = value;
                        } catch (Exception e) {
                            Logger.LogEceptionForce(new Exception(string.Format("key={0}, value={1}", key, value), e));
                        }
                    }
                }
            }
            WWW www = new WWW(wwwRequest.URL, form.data, headers);

            StartCoroutine(YieldWWW(www, new TaskAction(
                                        wwwCallback,
                                        new Dictionary <string, object>()
            {
                { CALLBACK_PARAM_CALLBACK, callback }, { CALLBACK_PARAM_REQUEST, wwwRequest }
            }
                                        )));
        }
Esempio n. 4
0
        public void Post(WWWRequest wwwRequest, WWWCallback callback)
        {
            WebRequest request = WebRequest.Create(wwwRequest.URL);

            request.Method = "POST";

            WWWAsynState state = new WWWAsynState(wwwRequest, callback, request);

            StartRequest(state);
        }
Esempio n. 5
0
 public void Load(string url, WWWCallback callback, string filename, WWWProgress progress = null, WWWForm form = null)
 {
     Load(url, delegate(WWW www) {
         if (filename != null)
         {
             Utils.it.SaveFile(filename, www.bytes);
         }
         callback(www);
     }, progress, form);
 }
Esempio n. 6
0
        public void LoadURL(string strURL, WWWCallback callback, object param = null, bool bCache = false)
        {
            WWWRequest req = new WWWRequest();

            req.strURL   = strURL;
            req.callback = callback;
            req.m_bCache = bCache;
            req.m_param  = param;
            wwwRequest.Add(req);
            checkQueue();
        }
Esempio n. 7
0
        private IEnumerator onLoad(string url, WWWCallback callback, WWWProgress progress, WWWForm form = null)
        {
            WWW www = form != null ? new WWW(url, form) : new WWW(url);

            while (!www.isDone)
            {
                if (progress != null)
                {
                    progress(www.progress);
                }
                yield return(new WaitForEndOfFrame());
            }
            callback(www);
        }
Esempio n. 8
0
        public void Get(WWWRequest wwwRequest, WWWCallback callback)
        {
            bool isWebplayer = false;

#if UNITY_WEBPLAYER
            isWebplayer = true;
#endif
            if (wwwRequest.Init.Count > 0 && isWebplayer)
            {
                wwwRequest.Parameters.Add(WWWConsts.PARAMETER_KEY_METHOD, WWWConsts.PARAMETER_KEY_GET);
                Post(wwwRequest, callback);
            }
            else
            {
                if (!string.IsNullOrEmpty(wwwRequest.Proxy))
                {
                    wwwRequest.Parameters[WWWConsts.REQUEST_CONTENT_TYPE_PROXY] = wwwRequest.Init[WWWConsts.REQUEST_CONTENT_TYPE];
                    wwwRequest.Init[WWWConsts.REQUEST_CONTENT_TYPE]             = "application/x-www-form-urlencoded";
                }

                Hashtable headers = new Hashtable();
                {
                    IDictionaryEnumerator enumerator = wwwRequest.Init.GetEnumerator();
                    while (enumerator.MoveNext())
                    {
                        object key   = enumerator.Key;
                        object value = enumerator.Value;
                        if (key != null && value != null)
                        {
                            headers[key] = value;
                        }
                    }
                }

                WWW www = new WWW(wwwRequest.FullURL, null, headers);

                StartCoroutine(YieldWWW(www, new TaskAction(
                                            wwwCallback,
                                            new Dictionary <string, object>()
                {
                    { CALLBACK_PARAM_CALLBACK, callback }, { CALLBACK_PARAM_REQUEST, wwwRequest }
                }
                                            )));
            }
        }
Esempio n. 9
0
        protected void StartRequestInternal(WWW request, WWWCallback callback)
        {
            m_Request  = request;
            m_Callback = callback;

            if (!Application.isPlaying)
            {
#if UNITY_EDITOR
                UnityEditor.EditorApplication.update += WaitForRequestInEditor;
#else
                StartCoroutine(WaitForRequest());
#endif
            }
            else
            {
                StartCoroutine(WaitForRequest());
            }
        }
Esempio n. 10
0
    public static void Post(string url, Hashtable formData, WWWCallback callback)
    {
        if (formData == null)
        {
            formData = new Hashtable();
        }
        formData["userid"]    = User.Instance.id.ToString();
        formData["distance"]  = GeoLocation.distance.ToString();
        formData["latitude"]  = GeoLocation.userLatitude.ToString();
        formData["longitude"] = GeoLocation.userLongitude.ToString();
        formData["os"]        = Application.platform.ToString();

        foreach (DictionaryEntry entry in formData)
        {
            //MyDebug.LogFormat("{0} {1}", entry.Key, entry.Value);
        }

        Init(url, formData, callback);
    }
Esempio n. 11
0
 public WWWAsynState(WWWRequest wRequest, WWWCallback callback, WebRequest request)
 {
     WRequest = wRequest;
     Callback = callback;
     Request  = request;
 }
Esempio n. 12
0
 public void Load(string url, WWWCallback callback, WWWProgress progress = null, WWWForm form = null)
 {
     Debug.Log(url);
     StartCoroutine(onLoad(url, callback, progress, form));
 }
Esempio n. 13
0
 public static void Post(REQUESTTYPE type, Hashtable formData, WWWCallback callback = null)
 {
     Post(GetURLByType(type), formData, callback);
 }
Esempio n. 14
0
        public static WWWUtility StartRequest(string url, byte[] postData, Dictionary <string, string> headers, WWWCallback callback, object metaData)
        {
            WWW www;

            if (postData != null && headers != null)
            {
                www = new WWW(url, postData, headers);
            }
            else
            {
                www = new WWW(url);
            }

            var util = CreateTempBehavior();

            util.m_metaData = metaData;
            util.StartRequestInternal(www, callback);
            return(util);
        }
Esempio n. 15
0
 public static WWWUtility StartRequest(string url, byte[] postData, Dictionary <string, string> headers, WWWCallback callback)
 {
     return(StartRequest(url, postData, headers, callback, null));
 }
Esempio n. 16
0
 public static WWWUtility StartRequest(string url, WWWCallback callback, object metaData)
 {
     return(StartRequest(url, null, null, callback, metaData));
 }
Esempio n. 17
0
 public static WWWUtility StartRequest(string url, WWWCallback callback)
 {
     return(StartRequest(url, null, null, callback));
 }
Esempio n. 18
0
 public static void Get(string url, WWWCallback callback)
 {
     Init(url, null, callback);
 }
Esempio n. 19
0
 public static void Get(REQUESTTYPE type, WWWCallback callback)
 {
     Get(GetURLByType(type), callback);
 }
Esempio n. 20
0
 public static void PostStatic(WWWRequest wwwConfig, WWWCallback callback)
 {
     Instance.Post(wwwConfig, callback);
 }