예제 #1
0
        /// <summary>
        /// 创建 Web 请求任务。
        /// </summary>
        /// <param name="webRequestUri">要发送的远程地址。</param>
        /// <param name="postData">要发送的数据流。</param>
        /// <param name="priority">Web 请求任务的优先级。</param>
        /// <param name="timeout">下载超时时长,以秒为单位。</param>
        /// <param name="userData">用户自定义数据。</param>
        /// <returns>创建的 Web 请求任务。</returns>
        public static WebRequestTask Create(string webRequestUri, byte[] postData, int priority, float timeout, object userData)
        {
            WebRequestTask webRequestTask = ReferencePool.Acquire <WebRequestTask>();

            webRequestTask.Initialize(++s_Serial, priority);
            webRequestTask.m_WebRequestUri = webRequestUri;
            webRequestTask.m_PostData      = postData;
            webRequestTask.m_Timeout       = timeout;
            webRequestTask.m_UserData      = userData;
            return(webRequestTask);
        }
예제 #2
0
        /// <summary>
        /// 增加 Web 请求任务。
        /// </summary>
        /// <param name="webRequestUri">Web 请求地址。</param>
        /// <param name="postData">要发送的数据流。</param>
        /// <param name="priority">Web 请求任务的优先级。</param>
        /// <param name="userData">用户自定义数据。</param>
        /// <returns>新增 Web 请求任务的序列编号。</returns>
        public int AddWebRequest(string webRequestUri, byte[] postData, int priority, object userData)
        {
            if (string.IsNullOrEmpty(webRequestUri))
            {
                Debug.Log("Web request uri is invalid.");
            }

            if (TotalAgentCount <= 0)
            {
                Debug.Log("You must add web request agent first.");
            }

            WebRequestTask webRequestTask = WebRequestTask.Create(webRequestUri, postData, priority, m_Timeout, userData);

            m_TaskPool.AddTask(webRequestTask);
            return(webRequestTask.SerialId);
        }