static async Task Main(string[] args) { var enrollmentNumber = ConfigurationManager.AppSettings["enrollment"]; var accessToken = ConfigurationManager.AppSettings["token"]; _httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("text/csv")); _httpClient.DefaultRequestHeaders.Add("Authorization", "Bearer " + accessToken); // var responseStream = await _httpClient.GetStreamAsync($"enrollments/{enrollmentNumber}/usagedetails/download?billingPeriod=201902"); // var responseMessage = await _httpClient.GetAsync($"enrollments/{enrollmentNumber}/usagedetails/download?billingPeriod=201902"); // var pipeHttpClient = new PipeHttpClient( ); IPHostEntry ipHostInfo = Dns.GetHostEntry("consumption.azure.com"); using (var clientSocketPipe = await SocketPipe.ConnectAsync(ipHostInfo.HostName, 443, false)) { var pipeHttpClient = new PipeHttpClient(clientSocketPipe); // var request = new GetFileRequest($"v3/enrollments/{enrollmentNumber}/usagedetails/download?billingPeriod=201902", accessToken); var request = new GetFileRequest($"v3/enrollments/{enrollmentNumber}/billingPeriods", accessToken); try { StorageResponse response = await pipeHttpClient.SendRequest <GetFileRequest, StorageResponse>(request); if (response.StatusCode != 200) { } } catch (Exception ex) { var msg = ex.Message; } //ulong bytesToRead = response.ContentLength; //using (var file = new FileStream(localFilePath, FileMode.Create, FileAccess.Write, FileShare.None, 4096, FileOptions.Asynchronous)) //{ // await file.WriteAsync(response.Body, bytesToRead); //} } }
//internal Sha256 Hash => _hash; public async ValueTask <StorageResponse> SendRequest <TRequest>(TRequest request) where TRequest : IStorageRequest { if (!_client.IsConnected) { _pipe = await SocketPipe.ConnectAsync(_host, _port).ConfigureAwait(false); _pipe.Log = Log; _client = new PipeHttpClient(_pipe); } request.Client = this; StorageResponse response = await _client.SendRequest <TRequest, StorageResponse>(request).ConfigureAwait(false); if (request.ConsumeBody) { await ConsumeResponseBody(response.Body); } return(response); }