public static string GetBlueStacksVersionId() { if (string.IsNullOrEmpty(GuidUtils.sBlueStacksVersionId)) { GuidUtils.sBlueStacksVersionId = StringUtils.GetControlCharFreeString(GuidUtils.GetIdFromRegistryOrFile("VersionMachineId_4.250.0.1070").Trim()); } return(GuidUtils.sBlueStacksVersionId); }
private static string PostInternal( string url, Dictionary <string, string> data, Dictionary <string, string> headers, bool gzip, int timeout, NameValueCollection headerCollection, string userAgent) { HttpWebRequest httpWebRequest = WebRequest.Create(url) as HttpWebRequest; httpWebRequest.Method = "POST"; if (timeout != 0) { httpWebRequest.Timeout = timeout; } if (gzip) { httpWebRequest.AutomaticDecompression = DecompressionMethods.GZip; httpWebRequest.Headers.Add(HttpRequestHeader.AcceptEncoding, nameof(gzip)); } if (headerCollection != null) { httpWebRequest.Headers.Add(headerCollection); } if (!string.IsNullOrEmpty(userAgent)) { httpWebRequest.UserAgent = userAgent; } if (headers != null) { foreach (KeyValuePair <string, string> header in headers) { httpWebRequest.Headers.Set(StringUtils.GetControlCharFreeString(header.Key), StringUtils.GetControlCharFreeString(header.Value)); } } if (data == null) { data = new Dictionary <string, string>(); } byte[] bytes = Encoding.UTF8.GetBytes(StringUtils.Encode(data)); httpWebRequest.ContentType = "application/x-www-form-urlencoded"; httpWebRequest.ContentLength = (long)bytes.Length; using (Stream requestStream = httpWebRequest.GetRequestStream()) { requestStream.Write(bytes, 0, bytes.Length); using (HttpWebResponse response = httpWebRequest.GetResponse() as HttpWebResponse) { Logger.Debug("Response StatusCode:" + response.StatusCode.ToString()); using (Stream responseStream = response.GetResponseStream()) { using (StreamReader streamReader = new StreamReader(responseStream, Encoding.UTF8)) return(streamReader.ReadToEnd()); } } } }
private static string GetInternal( string url, Dictionary <string, string> headers, bool gzip, int timeout, NameValueCollection headerCollection = null, string userAgent = "") { HttpWebRequest httpWebRequest = WebRequest.Create(url) as HttpWebRequest; httpWebRequest.Method = "GET"; if (timeout != 0) { httpWebRequest.Timeout = timeout; } if (gzip) { httpWebRequest.AutomaticDecompression = DecompressionMethods.GZip; httpWebRequest.Headers.Add(HttpRequestHeader.AcceptEncoding, nameof(gzip)); } if (headerCollection != null) { httpWebRequest.Headers.Add(headerCollection); } if (!string.IsNullOrEmpty(userAgent)) { httpWebRequest.UserAgent = userAgent; } if (headers != null) { foreach (KeyValuePair <string, string> header in headers) { httpWebRequest.Headers.Set(StringUtils.GetControlCharFreeString(header.Key), StringUtils.GetControlCharFreeString(header.Value)); } } using (HttpWebResponse response = httpWebRequest.GetResponse() as HttpWebResponse) { Logger.Debug("Response StatusCode:" + response.StatusCode.ToString()); using (Stream responseStream = response.GetResponseStream()) { using (StreamReader streamReader = new StreamReader(responseStream, Encoding.UTF8)) return(streamReader.ReadToEnd()); } } }
private static string HttpUploadFileInternal( string url, string file, string paramName, string contentType, Dictionary <string, string> headers, Dictionary <string, string> data) { Logger.Info("Uploading {0} to {1}", (object)file, (object)url); string str1 = "---------------------------" + DateTime.Now.Ticks.ToString("x", (IFormatProvider)CultureInfo.InvariantCulture); byte[] bytes1 = Encoding.ASCII.GetBytes("\r\n--" + str1 + "\r\n"); Uri destination = new Uri(url); HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url); httpWebRequest.ContentType = "multipart/form-data; boundary=" + str1; httpWebRequest.Method = "POST"; httpWebRequest.KeepAlive = true; httpWebRequest.Timeout = 300000; httpWebRequest.UserAgent = Utils.GetUserAgent("bgp"); if (!destination.Host.Contains("localhost") && !destination.Host.Contains("127.0.0.1")) { Uri proxy = httpWebRequest.Proxy.GetProxy(destination); Logger.Debug("URI of proxy = " + ((object)proxy != null ? proxy.ToString() : (string)null)); } if (headers != null) { foreach (KeyValuePair <string, string> header in headers) { httpWebRequest.Headers.Set(StringUtils.GetControlCharFreeString(header.Key), StringUtils.GetControlCharFreeString(header.Value)); } } httpWebRequest.Headers.Add(HTTPUtils.GetRequestHeaderCollection("")); if (data == null) { data = new Dictionary <string, string>(); } Stream requestStream = httpWebRequest.GetRequestStream(); string format = "Content-Disposition: form-data; name=\"{0}\"\r\n\r\n{1}"; foreach (KeyValuePair <string, string> keyValuePair in data) { requestStream.Write(bytes1, 0, bytes1.Length); byte[] bytes2 = Encoding.UTF8.GetBytes(string.Format((IFormatProvider)CultureInfo.InvariantCulture, format, (object)keyValuePair.Key, (object)keyValuePair.Value)); requestStream.Write(bytes2, 0, bytes2.Length); } requestStream.Write(bytes1, 0, bytes1.Length); byte[] bytes3 = Encoding.UTF8.GetBytes(string.Format((IFormatProvider)CultureInfo.InvariantCulture, "Content-Disposition: form-data; name=\"{0}\"; filename=\"{1}\"\r\nContent-Type: {2}\r\n\r\n", (object)paramName, (object)file, (object)contentType)); requestStream.Write(bytes3, 0, bytes3.Length); string str2 = Path.Combine(Environment.ExpandEnvironmentVariables("%TEMP%"), Path.GetFileName(file)) + "_bst"; System.IO.File.Copy(file, str2); if (contentType.Equals("text/plain", StringComparison.InvariantCultureIgnoreCase)) { string s = System.IO.File.ReadAllText(str2); byte[] numArray = new byte[1048576]; byte[] bytes2 = Encoding.UTF8.GetBytes(s); requestStream.Write(bytes2, 0, bytes2.Length); } else { FileStream fileStream = new FileStream(str2, FileMode.Open, FileAccess.Read); byte[] buffer = new byte[4096]; int count; while ((count = fileStream.Read(buffer, 0, buffer.Length)) != 0) { requestStream.Write(buffer, 0, count); } fileStream.Close(); } System.IO.File.Delete(str2); byte[] bytes4 = Encoding.ASCII.GetBytes("\r\n--" + str1 + "--\r\n"); requestStream.Write(bytes4, 0, bytes4.Length); requestStream.Close(); string str3 = (string)null; WebResponse webResponse = (WebResponse)null; try { webResponse = httpWebRequest.GetResponse(); using (Stream responseStream = webResponse.GetResponseStream()) { using (StreamReader streamReader = new StreamReader(responseStream)) { str3 = streamReader.ReadToEnd(); Logger.Info("File uploaded, server response is: {0}", (object)str3); } } } catch (Exception ex) { Logger.Error("Error uploading file", (object)ex); webResponse?.Close(); throw; } finally { } return(str3); }