Пример #1
0
        /// <summary>
        /// POST request
        /// </summary>
        /// <param name="settings">HTTP settings</param>
        /// <param name="body">Body of post request</param>
        /// <typeparam name="T">Type of the body</typeparam>
        /// <returns>The request was success or not</returns>
        public async Task <bool> Create <T>(HttpSettings settings, HttpBody <T> body)
        {
            this.CheckSettings(settings);

            string url = this.CreateUrl(settings);

            HttpResponseMessage response;

            try
            {
                response = await this._httpClient.PostAsync(url, body.GetStringContent());
            }
            catch (Exception e)
            {
                this.ConsoleCallError(e, url);
                return(false);
            }

            // Optional toast
            if (settings.ToasterSettings.IsNeeded)
            {
                await this._helperService.AddToaster(response, settings.ToasterSettings.Caption);
            }

            return(response.IsSuccessStatusCode);
        }
Пример #2
0
        /// <summary>
        /// POST request where we want string response
        /// </summary>
        /// <param name="settings">HTTP settings</param>
        /// <param name="body">Body of post request</param>
        /// <typeparam name="T">Type of the body</typeparam>
        /// <returns>Response string value</returns>
        public async Task <string> CreateString <T>(HttpSettings settings, HttpBody <T> body)
        {
            this.CheckSettings(settings);

            string url = this.CreateUrl(settings);

            HttpResponseMessage response;

            try
            {
                response = await this._httpClient.PostAsync(url, body.GetStringContent());
            }
            catch (Exception e)
            {
                this.ConsoleCallError(e, url);
                return(default);