private string PerformRequest(string address, Method method, string accept, string?contentType, string?body = null) { Debug.Print($"[{DateTime.UtcNow}] WEB SERVICE REQUEST: {method} {this.BaseUri}{address}"); this.ClientLock.Wait(); try { var wc = this.WebClient; if (this.BearerToken != null) { wc.Headers.Set("Authorization", $"Bearer {this.BearerToken}"); } if (contentType != null) { wc.Headers.Set("Content-Type", contentType); } wc.Headers.Set("Accept", accept); wc.Headers.Set("User-Agent", this.FullUserAgent); wc.QueryString.Clear(); try { if (method == Method.GET) { return(wc.DownloadString(address)); } if (body != null) { Debug.Print($"[{DateTime.UtcNow}] => BODY ({contentType}): {body}"); } return(wc.UploadString(address, method.ToString(), body ?? string.Empty)); } catch (WebException we) { Query.MaybeMapException(we); throw; } } finally { this.ClientLock.Release(); } }