예제 #1
0
        public void Run()
        {
            Console.WriteLine(typeof(DemoTwo).Name);
            // 简单获取,异常需要自己捕捉
            string url  = "https://www.baidu.com/";
            string html = SimpleHttp.HttpGet(url);

            Console.WriteLine("简单请求:" + html.Substring(0, 10));
            Console.WriteLine();
        }
예제 #2
0
 public static IServiceCollection UseBlacklistFromAddress(this IServiceCollection services, string address)
 {
     AsyncHelper.TryAsync(async() =>
     {
         var list     = await SimpleHttp.DownloadAsString(address);
         var provider = new BlackListPorivder(list.Split('\n'));
         services.AddSingleton(provider);
     }, 3);
     return(services);
 }
예제 #3
0
 public static IServiceCollection AddWarpgateServer(this IServiceCollection services, string warpgateEndpoint)
 {
     AsyncHelper.TryAsync(async() =>
     {
         var response    = await SimpleHttp.DownloadAsString(warpgateEndpoint);
         var serverModel = JsonConvert.DeserializeObject <IndexViewModel>(response);
         services.AddSingleton(new WarpgateLocator(warpgateEndpoint, serverModel.WarpPattern));
     }, 5);
     services.AddLibraryDependencies();
     return(services);
 }
예제 #4
0
 public static IServiceCollection AddArchonServer(this IServiceCollection services, string serverEndpoint)
 {
     AsyncHelper.TryAsync(async() =>
     {
         var response    = await SimpleHttp.DownloadAsString(serverEndpoint);
         var serverModel = JsonConvert.DeserializeObject <IndexViewModel>(response);
         var publicKey   = new RSAParameters
         {
             Modulus  = serverModel.Modulus.Base64ToBytes(),
             Exponent = serverModel.Exponent.Base64ToBytes()
         };
         services.AddSingleton(new ArchonLocator(serverEndpoint, publicKey));
     }, 5);
     services.AddLibraryDependencies();
     return(services);
 }
예제 #5
0
        public static IServiceCollection AddProbeServer(
            this IServiceCollection services,
            string serverEndpoint)
        {
            AsyncHelper.TryAsync(async() =>
            {
                var serverConfigString = await SimpleHttp.DownloadAsString(serverEndpoint);
                var serverConfig       = JsonConvert.DeserializeObject <IndexViewModel>(serverConfigString);
                var openFormat         = serverConfig.OpenPattern;
                var downloadFormat     = serverConfig.DownloadPattern;
                var playerFormat       = serverConfig.PlayerPattern;
                services.AddSingleton(new ProbeLocator(serverEndpoint, openFormat, downloadFormat, playerFormat));
            }, 5);

            services.AddLibraryDependencies();
            return(services);
        }
예제 #6
0
    public static void TestUpload()
    {
        //1.请求Token,添加header验证
        Dictionary <string, string> form = new Dictionary <string, string>();

        form.Add("Authorization", "Bearer 9701d8d0-f932-4648-8d08-1fc9fff8b895");
        SimpleHttp.HttpPost(url, form, null, (WWW wwwInfo) =>
        {
            Debug.Log(wwwInfo.text);

            /**{
             *  "code": 200,
             *  "message": "success",
             *  "data": {
             *      "token": "xxxxxxxxxxxx"
             *  },
             *  "timestamp": "1573436429382"
             * }
             */
            JObject root = JObject.Parse(wwwInfo.text);
            int code     = Convert.ToInt32(root["code"]);
            if (code == 200)
            {
                //2.获得uptoken
                string uptoken     = Convert.ToString(root["data"]["token"]);
                string key         = string.Format("u3d.{0}.target", root["timestamp"]);
                string filePath    = Application.streamingAssetsPath + "/9924317EB4DC8E3E1A604108133F837D.target";
                string persistPath = Application.persistentDataPath + "/9924317EB4DC8E3E1A604108133F837D.target";

                File.Copy(filePath, persistPath, true);

                QiniuUtil.UploadFile(key, persistPath, uptoken, (string text) => {
                    Debug.Log(text);
                });
            }
        });
    }
예제 #7
0
    IEnumerator GetUrlList()
    {
        var args = string.Format("package={0}&app_version={1}&res_version={2}&notice_version={3}", ChannelManager.instance.packageName, ChannelManager.instance.appVersion, clientResVersion, ChannelManager.instance.noticeVersion);

        bool GetUrlListComplete = false;
        WWW  www = null;

        SimpleHttp.HttpPost(Setting.START_UP_URL, null, DataUtils.StringToBytes(args), (WWW wwwInfo) => {
            www = wwwInfo;
            GetUrlListComplete = true;
        });
        yield return(new WaitUntil(() =>
        {
            return GetUrlListComplete;
        }));

        if (www == null || !string.IsNullOrEmpty(www.error) || www.bytes == null || www.bytes.Length == 0)
        {
            Logger.LogError("Get url list for args {0} with err : {1}", args, www == null ? "www null" : (!string.IsNullOrEmpty(www.error) ? www.error : "bytes length 0"));
            yield return(GetUrlList());
        }

        var urlList = (Dictionary <string, object>)MiniJSON.Json.Deserialize(DataUtils.BytesToString(www.bytes));

        if (urlList == null)
        {
            Logger.LogError("Get url list for args {0} with err : {1}", args, "Deserialize url list null!");
            yield return(GetUrlList());
        }

        if (urlList.ContainsKey("serverlist"))
        {
            Setting.SERVER_LIST_URL = urlList["serverlist"].ToString();
        }
        if (urlList.ContainsKey("verifying"))
        {
            Setting.LOGIN_URL = urlList["verifying"].ToString();
        }
        if (urlList.ContainsKey("logserver"))
        {
            Setting.REPORT_ERROR_URL = urlList["logserver"].ToString();
        }
        if (urlList.ContainsKey("res_version") && !string.IsNullOrEmpty(urlList["res_version"].ToString()))
        {
            serverResVersion = urlList["res_version"].ToString();
        }
        if (urlList.ContainsKey("notice_version") && !string.IsNullOrEmpty(urlList["notice_version"].ToString()))
        {
            ChannelManager.instance.noticeVersion = urlList["notice_version"].ToString();
            GameUtility.SafeWriteAllText(noticeVersionPath, ChannelManager.instance.noticeVersion);
        }
        if (urlList.ContainsKey("notice_url") && !string.IsNullOrEmpty(urlList["notice_url"].ToString()))
        {
            noticeUrl = urlList["notice_url"].ToString();
        }
        if (urlList.ContainsKey("app") && !string.IsNullOrEmpty(urlList["app"].ToString()))
        {
            Setting.APP_ADDR = urlList["app"].ToString();
            needDownloadGame = true;
        }
        else if (urlList.ContainsKey("res") && !string.IsNullOrEmpty(urlList["res"].ToString()))
        {
            Setting.SERVER_RESOURCE_ADDR = urlList["res"].ToString();
            needUpdateGame = true;
        }

#if UNITY_CLIENT || LOGGER_ON
        System.Text.StringBuilder sb = new System.Text.StringBuilder();
        sb.AppendFormat("SERVER_LIST_URL = {0}\n", Setting.SERVER_LIST_URL);
        sb.AppendFormat("LOGIN_URL = {0}\n", Setting.LOGIN_URL);
        sb.AppendFormat("REPORT_ERROR_URL = {0}\n", Setting.REPORT_ERROR_URL);
        sb.AppendFormat("NOTIFY_URL = {0}\n", Setting.NOTIFY_URL);
        sb.AppendFormat("NOTIFY_URL1 = {0}\n", Setting.NOTIFY_URL1);
        sb.AppendFormat("APP_ADDR = {0}\n", Setting.APP_ADDR);
        sb.AppendFormat("SERVER_RESOURCE_ADDR = {0}\n", Setting.SERVER_RESOURCE_ADDR);
        sb.AppendFormat("noticeVersion = {0}\n", ChannelManager.instance.noticeVersion);
        sb.AppendFormat("serverResVersion = {0}\n", serverResVersion);
        sb.AppendFormat("noticeUrl = {0}\n", noticeUrl);
        Logger.Log(sb.ToString());
#endif
        yield break;
    }
예제 #8
0
    IEnumerator OutnetGetUrlList()
    {
        var args = string.Format("package={0}&app_version={1}&res_version={2}&notice_version={3}", ChannelManager.instance.channelName, ChannelManager.instance.appVersion, clientResVersion, ChannelManager.instance.noticeVersion);

        bool GetUrlListComplete = false;
        WWW  www = null;

        SimpleHttp.HttpPost(URLSetting.START_UP_URL, null, UtilityData.StringToBytes(args), (WWW wwwInfo) => {
            www = wwwInfo;
            GetUrlListComplete = true;
        });
        yield return(new WaitUntil(() =>
        {
            return GetUrlListComplete;
        }));

        if (www == null || !string.IsNullOrEmpty(www.error) || www.bytes == null || www.bytes.Length == 0)
        {
            Logger.LogError("Get url list for args {0} with err : {1}", args, www == null ? "www null" : (!string.IsNullOrEmpty(www.error) ? www.error : "bytes length 0"));
            yield return(OutnetGetUrlList());
        }

        var urlList = (Dictionary <string, object>)MiniJSON.Json.Deserialize(UtilityData.BytesToString(www.bytes));

        if (urlList == null)
        {
            Logger.LogError("Get url list for args {0} with err : {1}", args, "Deserialize url list null!");
            yield return(OutnetGetUrlList());
        }

        if (urlList.ContainsKey("serverlist"))
        {
            URLSetting.SERVER_LIST_URL = urlList["serverlist"].ToString();
        }
        if (urlList.ContainsKey("verifying"))
        {
            URLSetting.LOGIN_URL = urlList["verifying"].ToString();
        }
        if (urlList.ContainsKey("logserver"))
        {
            URLSetting.REPORT_ERROR_URL = urlList["logserver"].ToString();
        }
        if (urlList.ContainsKey("app_version") && !string.IsNullOrEmpty(urlList["app_version"].ToString()))
        {
            serverAppVersion = urlList["app_version"].ToString();
        }
        if (urlList.ContainsKey("res_version") && !string.IsNullOrEmpty(urlList["res_version"].ToString()))
        {
            serverResVersion = urlList["res_version"].ToString();
        }
        if (urlList.ContainsKey("notice_version") && !string.IsNullOrEmpty(urlList["notice_version"].ToString()))
        {
            ChannelManager.instance.noticeVersion = urlList["notice_version"].ToString();
            UtilityGame.SafeWriteAllText(noticeVersionPath, ChannelManager.instance.noticeVersion);
        }
        if (urlList.ContainsKey("notice_url") && !string.IsNullOrEmpty(urlList["notice_url"].ToString()))
        {
            URLSetting.NOTICE_URL = urlList["notice_url"].ToString();
        }
        if (urlList.ContainsKey("app") && !string.IsNullOrEmpty(urlList["app"].ToString()))
        {
            URLSetting.APP_DOWNLOAD_URL = urlList["app"].ToString();
        }
        else if (urlList.ContainsKey("res") && !string.IsNullOrEmpty(urlList["res"].ToString()))
        {
            URLSetting.SERVER_RESOURCE_URL = urlList["res"].ToString();
        }
        yield break;
    }