Untitled

mail@pastecode.io avatar
unknown
plain_text
19 days ago
1.1 kB
2
Indexable
Never
 public async Task<HttpResponseMessage> SendToSapAsync(HttpContent httpContent, Uri apiUri, Uri authorizationUri)
        {
            var httpClient = new HttpClient();
            if (this.executionContext.IsDemo)
            {
                return new HttpResponseMessage(HttpStatusCode.Accepted);
            }

            string bearerToken = await this.GetAuthorizationBearerToken(authorizationUri).ConfigureAwait(false);
            if (httpContent != null)
            {
                httpContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");
            }

            httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", bearerToken);
            var httpresponse = await httpClient.PutAsync(apiUri, httpContent).ConfigureAwait(false);
            this.logger.LogMessage(
                  EventLevel.Informational,
                  string.Empty,
                  $"GTS Sap Integration - for the input {httpContent} responsecode {httpresponse.StatusCode}");

            return httpresponse;
        }
Leave a Comment