50 lines
1.8 KiB
C#
50 lines
1.8 KiB
C#
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
using Volo.Abp.Content;
|
|||
|
using Volo.Abp.Http.Client.ClientProxying;
|
|||
|
using Volo.Abp.Http.Client.DynamicProxying;
|
|||
|
|
|||
|
namespace Syc.Abp.HttpApi.Client
|
|||
|
{
|
|||
|
public class AppDynamicHttpProxyInterceptorClientProxy<TService> : DynamicHttpProxyInterceptorClientProxy<TService>
|
|||
|
{
|
|||
|
public override async Task<T> CallRequestAsync<T>(ClientProxyRequestContext requestContext)
|
|||
|
{
|
|||
|
var result = await RequestAsync<Response<T>>(requestContext);
|
|||
|
return result.Data;
|
|||
|
}
|
|||
|
|
|||
|
protected override async Task<T> RequestAsync<T>(ClientProxyRequestContext requestContext)
|
|||
|
{
|
|||
|
var responseContent = await RequestAsync(requestContext);
|
|||
|
|
|||
|
if (typeof(T) == typeof(IRemoteStreamContent) ||
|
|||
|
typeof(T) == typeof(RemoteStreamContent))
|
|||
|
{
|
|||
|
return (T)(object)new RemoteStreamContent(
|
|||
|
await responseContent.ReadAsStreamAsync(),
|
|||
|
responseContent.Headers?.ContentDisposition?.FileNameStar ??
|
|||
|
RemoveQuotes(responseContent.Headers?.ContentDisposition?.FileName).ToString(),
|
|||
|
responseContent.Headers?.ContentType?.ToString(),
|
|||
|
responseContent.Headers?.ContentLength);
|
|||
|
}
|
|||
|
|
|||
|
var stringContent = await responseContent.ReadAsStringAsync();
|
|||
|
if (typeof(T) == typeof(string))
|
|||
|
{
|
|||
|
return (T)(object)stringContent;
|
|||
|
}
|
|||
|
|
|||
|
if (stringContent.IsNullOrWhiteSpace())
|
|||
|
{
|
|||
|
return default;
|
|||
|
}
|
|||
|
var type = typeof(T);
|
|||
|
return Newtonsoft.Json.JsonConvert.DeserializeObject<T>(stringContent);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|