using LittleCow.Core.Autofac; using LittleCow.Core.DependencyInjection; using LittleCow.Core.Helpers; using LittleCow.Core.Logger; using LittleCow.Server.Commons; using LittleCow.Server.Extensions; using MAX.Core.DependencyInjection; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Text; using System.Threading.Tasks; using Trade.Client; using Trade.Client.Helpers; namespace Trade.Client.HttpExtension { public class ServerReqeustBase : ITransientDependency { /// /// 日志 /// [Autowired] protected ILoggerFacade _log { get; set; } /// /// 服务器配置 /// [Autowired] protected IServerConfig _config { get; set; } public ServerReqeustBase() { } public string BuildObjString(string urlpath) { return _config.Host + "?" + _config.ObjUrl + urlpath; } /// /// 服务器请求 /// /// /// public HttpResult ServerRequest(ServerHttpItem item) { #if RELEASE item.WebProxy = null; #endif if (!item.URL.StartsWith("http")) { item.URL += _config.Host + item.URL; } item.Encoding = Encoding.UTF8; if (item.Method == MethodType.Post) { item.ContentType = "application/x-www-form-urlencoded"; } if (!item.IsSign) { if (item.Shop != null) item.SignUser(item.Shop.Id, item.Shop.MainAccount); else item.Sign(); } HttpResult result = HttpHelper.Request(item); if (result.StatusCode == HttpStatusCode.OK) { if (!string.IsNullOrEmpty(result.Html)) { if (result.Html[0] == 65279) { result.Html = result.Html.Remove(0, 1); } } } else { } return result; } public async Task ServerAsyncRequest(ServerHttpItem item) { return await Task.FromResult(ServerRequest(item)); } } }