95 lines
1.9 KiB
C#
95 lines
1.9 KiB
C#
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
|
|
{
|
|
|
|
/// <summary>
|
|
/// 日志
|
|
/// </summary>
|
|
[Autowired]
|
|
protected ILoggerFacade _log { get; set; }
|
|
|
|
/// <summary>
|
|
/// 服务器配置
|
|
/// </summary>
|
|
[Autowired]
|
|
protected IServerConfig _config { get; set; }
|
|
|
|
public ServerReqeustBase()
|
|
{
|
|
}
|
|
|
|
public string BuildObjString(string urlpath)
|
|
{
|
|
return _config.Host + "?" + _config.ObjUrl + urlpath;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 服务器请求
|
|
/// </summary>
|
|
/// <param name="item"></param>
|
|
/// <returns></returns>
|
|
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<HttpResult> ServerAsyncRequest(ServerHttpItem item)
|
|
{
|
|
return await Task.FromResult(ServerRequest(item));
|
|
}
|
|
}
|
|
}
|