Exemplo n.º 1
0
        public async Task HttpDeleteServices <T>(string url, T t, string token = null)
        {
            GetOriginFromUri(url);
            string errorMsg = string.Empty;

            try
            {
                var response = await _httpClient.DeleteTAsync(url, t, token);

                //if (response.IsSuccessStatusCode)
                {
                    string responseContent = await response.Content.ReadAsStringAsync();

                    if (!string.IsNullOrEmpty(responseContent) /*&& JsonHelper.IsJson(responseContent)*/)
                    {
                        var result = JsonHelper.ToObject <AjaxResponse>(responseContent);
                        if (result.Success)
                        {
                            return;
                        }
                        errorMsg = result.Error.Message;
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.Error($"HttpDeleteServices{url}调用其他服务接口错误:{ ex.Message }");
                _logger.Error($"HttpDeleteServices{url}调用其他服务接口错误:{ ex.StackTrace }");
                throw new UserFriendlyException($"HttpDeleteServices{url}调用其他服务接口错误:{ ex.Message }");
            }

            _logger.Error($"HttpDeleteServices{url}调用其他服务接口错误:" + errorMsg);
            throw new UserFriendlyException(errorMsg);
        }