2025-03-28 09:49:56 +08:00

89 lines
3.3 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.NetworkInformation;
using System.Text;
using System.Threading.Tasks;
namespace GetHttpData.SDK
{
public class HttpDataHelper
{
#region -> Json方式添加数据()
/// <summary>
/// 通过Json方式添加数据
/// Mr.Cai 2018-1-3
/// </summary>
/// <param name="ipAddress">完整请求地址</param>
/// <param name="interfaceName">接口名字</param>
/// <param name="tableName">表名</param>
/// <param name="code">授权码</param>
/// <param name="jsonString">json参数数组</param>
/// <param name="orderString">其它参数</param>
/// <param name="outTime">超时时间</param>
/// <returns></returns>
public static string InsertDataByJson(string ipAddress, string interfaceName,
string tableName, string code, string jsonString, string orderString = "",int outTime = 60)
{
if (string.IsNullOrEmpty(ipAddress) || string.IsNullOrEmpty(interfaceName)
|| string.IsNullOrEmpty(tableName) || string.IsNullOrEmpty(jsonString))
{
throw new Exception("请求地址、接口名、表名或请求参数不可为空!");
}
try
{
//string[] args = { code, tableName, josnString, orderString };
//return WSHelper.InvokeWebService(ipAddress, interfaceName, args).ToString();
System.Collections.Hashtable hashtable = new System.Collections.Hashtable
{
{ "code", code},
{ "tableName" , tableName},
{ "jsonString" , jsonString},
{"orderString" , orderString }
};
return ESSupport.Lib.SoapWSHelper.QuerySoapWebServiceString(ipAddress, interfaceName, hashtable, outTime);
}
catch (Exception ex)
{
throw new Exception("网络请求失败:" + ex.ToString());
}
}
#endregion
#region -> Json方式添加数据()
/// <summary>
/// 通过Json方式添加数据
/// Mr.Cai 2018-1-3
/// </summary>
/// <param name="ipAddress">请求地址</param>
/// <param name="interfaceName">接口名字</param>
/// <param name="code">授权码</param>
/// <param name="jsonString">json参数数组</param>
/// <returns></returns>
public static string InsertDataByJson(string ipAddress, string interfaceName, string code, string jsonString)
{
if (string.IsNullOrEmpty(ipAddress) || string.IsNullOrEmpty(interfaceName) || string.IsNullOrEmpty(jsonString))
{
return "请求地址、接口名或请求参数不可为空!";
}
try
{
string[] args = { code, jsonString };
string _ServiceUrl = string.Format("http://{0}/TableDataService/Service.asmx", ipAddress);
return WSHelper.InvokeWebService(_ServiceUrl, interfaceName, args).ToString();
}
catch (Exception ex)
{
return "网络请求失败:" + ex.ToString();
}
}
#endregion
}
}