45 lines
1.0 KiB
C#
45 lines
1.0 KiB
C#
using BS.Shared.DataContracts;
|
|
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace BS.Shared.AppSender
|
|
{
|
|
public static class AppRequestSender
|
|
{
|
|
public static T2 Send<T, T2>(T request, string url, string tenant) where T : AppRequestDC where T2 : AppResponseDC
|
|
{
|
|
request.Tenant = tenant;
|
|
|
|
var data = JsonConvert.SerializeObject(request);
|
|
|
|
var response_app8_str = Send(url, data, tenant);
|
|
|
|
if (string.IsNullOrEmpty(response_app8_str))
|
|
return null;
|
|
|
|
return JsonConvert.DeserializeObject<T2>(response_app8_str);
|
|
}
|
|
|
|
private static string Send(string url, string dataString, string tenant)
|
|
{
|
|
string response_app8_str;
|
|
|
|
url += "?tenant=" + tenant;
|
|
|
|
using (WebClient client = new WebClient())
|
|
{
|
|
client.Headers.Add(HttpRequestHeader.ContentType, "application/json");
|
|
|
|
response_app8_str = client.UploadString(url, "POST", dataString);
|
|
}
|
|
|
|
return response_app8_str;
|
|
}
|
|
}
|
|
}
|