public static string PostJson(string url, string rawJsonObject, CredentialCache credentials, CachedAuthentication cachedAuth) { string json_response = string.Empty; using (WebClient client = new WebClient()) {//todo: understand 'using' better foreach(Cookie cookie in cachedAuth.cookies) { client.Headers.Add(cookie.Name, cookie.Value);} client.Headers[HttpRequestHeader.ContentType] = "application/json"; client.Credentials = credentials; byte[] byte_response = client.UploadData(url, Encoding.UTF8.GetBytes(rawJsonObject)); json_response = Encoding.UTF8.GetString(byte_response); } return json_response; }
public static bool Initialize(TaiConfig config) { BASE_URL = config["apiUrl"] ?? BASE_URL; try{ CACHED_AUTH = GetCachedAuthentication(config["username"], config["password"]); }catch{ Console.WriteLine("No Internet Connection");//meah Environment.Exit(0); } return true; }