コード例 #1
0
        public static Network.RequestResults RequestAPIImmediate(WebAPI api, bool autoRetry)
        {
            MonoSingleton <Network> .Instance.mImmediateMode = true;
            HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(Network.Host + api.name);

            httpWebRequest.ContentType = "application/json; charset=utf-8";
            httpWebRequest.Timeout     = (int)((double)Network.WEBAPI_TIMEOUT_SEC * 1000.0);
            httpWebRequest.Headers.Set("X-GUMI-TRANSACTION", api.GumiTransactionId);
            if (MonoSingleton <DebugManager> .Instance.IsWebViewEnable())
            {
                httpWebRequest.UserAgent = gu3.Device.System.GetUserAgent();
            }
            else
            {
                httpWebRequest.UserAgent = "Mozilla/5.0 (Linux; U; Android 4.3; ja-jp; Nexus 7 Build/JSS15Q) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Safari/534.30";
                DebugUtility.Log("Skip User-Agent");
            }
            if (!string.IsNullOrEmpty(Network.SessionID))
            {
                httpWebRequest.Headers.Add("Authorization", "gumi " + Network.SessionID);
            }
            if (!string.IsNullOrEmpty(Network.Version))
            {
                httpWebRequest.Headers.Add("x-app-ver", Network.Version);
            }
            if (!string.IsNullOrEmpty(Network.AssetVersion))
            {
                httpWebRequest.Headers.Add("x-asset-ver", Network.AssetVersion);
            }
            HttpWebResponse httpWebResponse = (HttpWebResponse)null;
            string          str             = (string)null;

            try
            {
                if (string.IsNullOrEmpty(api.body))
                {
                    httpWebRequest.Method = "GET";
                }
                else
                {
                    httpWebRequest.Method = "POST";
                    byte[] bytes = Encoding.UTF8.GetBytes(api.body);
                    httpWebRequest.ContentLength = (long)bytes.Length;
                    BinaryWriter binaryWriter = new BinaryWriter(httpWebRequest.GetRequestStream());
                    binaryWriter.Write(bytes);
                    binaryWriter.Close();
                }
                httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                Network.ErrCode = Network.EErrCode.Unknown;
                str             = new StreamReader(httpWebResponse.GetResponseStream(), true).ReadToEnd();
                Network.ErrCode = (Network.EErrCode)Network.FindStat(str);
                Network.ErrMsg  = Network.FindMessage(str);
            }
            catch (Exception ex)
            {
                Network.ErrCode = Network.EErrCode.Failed;
                Network.ErrMsg  = LocalizedText.Get("embed.NETWORKERR");
                Debug.LogException(ex);
            }
            finally
            {
                Network.IsError = Network.ErrCode != Network.EErrCode.Success;
                if (httpWebResponse != null)
                {
                    httpWebResponse.Close();
                }
            }
            Network.RequestResult = Network.RequestResults.Success;
            MonoSingleton <Network> .Instance.mCurrentRequest = (WebAPI)null;
            api.callback(new WWWResult(str));
            if (MonoSingleton <Network> .Instance.mImmediateMode)
            {
                MonoSingleton <Network> .Instance.mImmediateMode = false;
                if (autoRetry)
                {
                    --Network.TicketID;
                    Network.ResetError();
                    Network.RequestAPI(api, true);
                }
            }
            return(Network.RequestResult);
        }