Ejemplo n.º 1
0
        public static string Post(
            string url,
            Dictionary <string, string> data,
            Dictionary <string, string> headers,
            bool gzip,
            int retries,
            int sleepTimeMSecs,
            int timeout,
            NameValueCollection headerCollection,
            string userAgent)
        {
            string str = (string)null;
            int    num = retries;

            while (num > 0)
            {
                try
                {
                    str = HTTP.PostInternal(url, data, headers, gzip, timeout, headerCollection, userAgent);
                    break;
                }
                catch (Exception ex)
                {
                    if (num == 1)
                    {
                        throw;
                    }
                    else
                    {
                        Logger.Warning("Exception when posting to url: {0}, Ex: {1}", (object)url, (object)ex.Message);
                    }
                }
                --num;
                Thread.Sleep(sleepTimeMSecs);
            }
            return(str);
        }
Ejemplo n.º 2
0
        private static string PostInternal(
            string url,
            Dictionary <string, string> data,
            Dictionary <string, string> headers,
            bool gzip,
            int retries,
            int sleepTimeMSecs,
            int timeout,
            string vmName,
            bool isOnUIThreadOnPurpose,
            string oem = "bgp")
        {
            if (Thread.CurrentThread.ManagedThreadId == 1 && !isOnUIThreadOnPurpose)
            {
                Logger.Warning("WARNING: This network call is from UI Thread and its stack trace is {0}", (object)new StackTrace().ToString());
            }
            NameValueCollection headerCollection = HTTPUtils.GetRequestHeaderCollection(vmName);

            if (data == null)
            {
                data = new Dictionary <string, string>();
            }
            Uri uri = new Uri(url);

            if (uri.Host.Contains("localhost") || uri.Host.Contains("127.0.0.1"))
            {
                RegistryKey registryKey = RegistryUtils.InitKeyWithSecurityCheck("Software\\BlueStacks" + (oem.Equals("bgp", StringComparison.InvariantCultureIgnoreCase) ? "" : "_" + oem));
                headerCollection.Add("x_api_token", (string)registryKey.GetValue("ApiToken", (object)""));
            }
            else
            {
                headerCollection.Remove("x_api_token");
                data = Utils.AddCommonData(data);
            }
            return(HTTP.Post(url, data, headers, gzip, retries, sleepTimeMSecs, timeout, headerCollection, Utils.GetUserAgent(oem)));
        }