Exemplo n.º 1
0
        /// <ChangeLog>
        /// <Create Datum="15.10.2020" Entwickler="DA" />
        /// </ChangeLog>
        /// <summary>
        /// Sendet Daten im Post-Body
        /// </summary>
        protected async void SendDataPOST(Model.BaseModel data)
        {
            HttpClient         client  = new HttpClient();
            HttpRequestMessage request = new HttpRequestMessage
            {
                Method     = HttpMethod.Post,
                RequestUri = new Uri(Url),
                Content    = new StringContent(JsonConvert.SerializeObject(data), Encoding.UTF8, "application/json")
            };
            HttpResponseMessage response = await client.SendAsync(request).ConfigureAwait(false);

            response.EnsureSuccessStatusCode();
        }
Exemplo n.º 2
0
        /// <ChangeLog>
        /// <Create Datum="15.10.2020" Entwickler="DA" />
        /// </ChangeLog>
        /// <summary>
        /// Sendet Daten als JSON im Get-Body, deserialisiert aus dem zurückgekommenen JSON ein Objekt
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="data"></param>
        /// <returns></returns>
        /// <remarks>
        /// https://stackoverflow.com/questions/43421126/how-to-use-httpclient-to-send-content-in-body-of-get-request
        /// https://stackoverflow.com/a/47902348
        /// </remarks>
        protected async Task <T> SendDataGETReturnsModel <T>(Model.BaseModel data = null)
        {
            HttpClient client  = new HttpClient();
            var        request = new HttpRequestMessage
            {
                Method     = HttpMethod.Get,
                RequestUri = new Uri(Url),
                Content    = new StringContent(JsonConvert.SerializeObject(data), Encoding.UTF8, "application/json")
            };
            var response = await client.SendAsync(request).ConfigureAwait(false);

            response.EnsureSuccessStatusCode();
            var respBody = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

            return(JsonConvert.DeserializeObject <T>(respBody));
        }