mirror of https://github.com/abpframework/abp.git
5 changed files with 64 additions and 50 deletions
@ -1,6 +1,6 @@ |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace Volo.Abp.Http |
|||
namespace Volo.Abp.Http.Client.ClientProxying |
|||
{ |
|||
public interface IObjectToQueryString<in TValue> |
|||
{ |
|||
@ -0,0 +1,31 @@ |
|||
using System.Collections.Generic; |
|||
using System.Net.Http; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.Http.Client.ClientProxying; |
|||
using Volo.Abp.TestApp.Application.Dto; |
|||
|
|||
namespace Volo.Abp.Http.DynamicProxying |
|||
{ |
|||
[ExposeServices(typeof(IObjectToFormData<List<GetParamsNameValue>>))] |
|||
public class TestObjectToFormData : IObjectToFormData<List<GetParamsNameValue>>, ITransientDependency |
|||
{ |
|||
public Task<List<KeyValuePair<string, HttpContent>>> ConvertAsync(List<GetParamsNameValue> values) |
|||
{ |
|||
if (values.IsNullOrEmpty()) |
|||
{ |
|||
return null; |
|||
} |
|||
|
|||
var formDataContents = new List<KeyValuePair<string, HttpContent>>(); |
|||
for (var i = 0; i < values.Count; i++) |
|||
{ |
|||
formDataContents.Add(new KeyValuePair<string, HttpContent>($"NameValues[{i}].Name", new StringContent(values[i].Name, Encoding.UTF8))); |
|||
formDataContents.Add(new KeyValuePair<string, HttpContent>($"NameValues[{i}].Value", new StringContent(values[i].Value, Encoding.UTF8))); |
|||
} |
|||
|
|||
return Task.FromResult(formDataContents); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,31 @@ |
|||
using System.Collections.Generic; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.Http.Client.ClientProxying; |
|||
using Volo.Abp.TestApp.Application.Dto; |
|||
|
|||
namespace Volo.Abp.Http.DynamicProxying |
|||
{ |
|||
[ExposeServices(typeof(IObjectToQueryString<List<GetParamsNameValue>>))] |
|||
public class TestObjectToQueryString : IObjectToQueryString<List<GetParamsNameValue>>, ITransientDependency |
|||
{ |
|||
public Task<string> ConvertAsync(List<GetParamsNameValue> values) |
|||
{ |
|||
if (values.IsNullOrEmpty()) |
|||
{ |
|||
return null; |
|||
} |
|||
|
|||
var sb = new StringBuilder(); |
|||
|
|||
for (var i = 0; i < values.Count; i++) |
|||
{ |
|||
sb.Append($"NameValues[{i}].Name={values[i].Name}&NameValues[{i}].Value={values[i].Value}&"); |
|||
} |
|||
|
|||
sb.Remove(sb.Length - 1, 1); |
|||
return Task.FromResult(sb.ToString()); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue