public Stream HttpPost(string path, byte[] body, bool refreshTokenIfNeeded = true, string contentType = "text/xml")
        {
            var req = CreateRequest(path);

            req.Method      = "POST";
            req.ContentType = contentType;
            if (Config.IsDebugMode)
            {
                Debug.WriteLine(string.Empty);
                Debug.WriteLine("vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv");
                Debug.WriteLine("POST....");
                Debug.WriteLine("URL: " + url + path);
                Debug.WriteLine(req.Headers.ToString());
                Debug.WriteLine(body);
                Debug.WriteLine("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
                Debug.WriteLine("");
            }
            try
            {
                req.ContentLength = body.Length;
                req.GetRequestStream().Write(body, 0, body.Length);
                var resp = req.GetResponse();
                return(resp.GetResponseStream());
            }
            catch (WebException ex)
            {
                if (refreshTokenIfNeeded && ex.Status == WebExceptionStatus.ProtocolError)
                {
                    var authclient = new OAuth2Client.AuthClient(_secrets, EndpointScope);
                    _creds = authclient.refreshAuthCode(_creds);
                    return(HttpPost(path, body, refreshTokenIfNeeded: false));
                }
                throw;
            }
        }
        public Stream HttpGet(string path, bool refreshTokenIfNeeded = true, string contentType = "text/xml")
        {
            var req = CreateRequest(path);

            req.ContentType = contentType;
            req.Method      = "GET";


            try
            {
                var resp = req.GetResponse();

                if (Config.IsDebugMode)
                {
                    Debug.WriteLine(string.Empty);
                    Debug.WriteLine("vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv");
                    Debug.WriteLine("Get....");
                    Debug.WriteLine("URL: " + url + path);
                    Debug.WriteLine("Response from: " + resp.ResponseUri);
                    Debug.WriteLine(resp.Headers.ToString());
                    Debug.WriteLine(resp.ToString());
                    Debug.WriteLine("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
                    Debug.WriteLine(string.Empty);
                }


                return(resp.GetResponseStream());
            }
            catch (WebException ex)
            {
                var resp = (HttpWebResponse)ex.Response;
                if (refreshTokenIfNeeded && ex.Status == WebExceptionStatus.ProtocolError && resp.StatusCode == HttpStatusCode.Unauthorized)
                {
                    var authclient = new OAuth2Client.AuthClient(_secrets, EndpointScope);
                    _creds = authclient.refreshAuthCode(_creds);
                    return(HttpGet(path, refreshTokenIfNeeded: false));
                }
                throw;
            }
        }
 private void RefreshCreds()
 {
     _secrets = _storage.GetSecrets();
     _creds   = _storage.GetCredentials();
 }
		private void RefreshCreds()
		{
			_secrets = _storage.GetSecrets();
			_creds = _storage.GetCredentials();
		}
		public Stream HttpPost(string path, byte[] body, bool refreshTokenIfNeeded = true, string contentType = "text/xml")
		{
			var req = CreateRequest(path);
			req.Method = "POST";
			req.ContentType = contentType;
			if (Config.IsDebugMode)
			{
				Debug.WriteLine(string.Empty);
				Debug.WriteLine("vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv");
				Debug.WriteLine("POST....");
				Debug.WriteLine("URL: " + url + path);
				Debug.WriteLine(req.Headers.ToString());
				Debug.WriteLine(body);
				Debug.WriteLine("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
				Debug.WriteLine("");
			}
			try
			{
				req.ContentLength = body.Length;
				req.GetRequestStream().Write(body, 0, body.Length);
				var resp = req.GetResponse();
				return resp.GetResponseStream();
			}
			catch (WebException ex)
			{
				var resp = (HttpWebResponse)ex.Response;
				if (refreshTokenIfNeeded && ex.Status == WebExceptionStatus.ProtocolError && resp.StatusCode == HttpStatusCode.Unauthorized)
				{
					var authclient = new OAuth2Client.AuthClient(_secrets, EndpointScope);
					_creds = authclient.refreshAuthCode(_creds);
					_creds = _storage.StoreCredentials(_creds);
					return HttpPost(path, body, refreshTokenIfNeeded: false);
				}
				throw;
			}
		}