Commit 8feba3d1 LN

http修改

1 个父辈 37cce6d8
......@@ -95,7 +95,8 @@ namespace OnlineStore.ACSingleStore
{
log4net.GlobalContext.Properties["fname"] = ConfigAppSettings.GetValue(Setting_Init.Store_CID);
log4net.Config.XmlConfigurator.Configure();
// XmlConfigurator.Configure();
System.Net.ServicePointManager.DefaultConnectionLimit = 512;
// XmlConfigurator.Configure();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new FrmStoreBox());
......
......@@ -20,28 +20,11 @@ namespace OnlineStore.Common
{
public static readonly ILog LOGGER = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
public static Operation Post(string url, Operation operation,out bool isTimeOut)
public static Operation PostOP(string url, Operation operation,out bool isTimeOut)
{
isTimeOut = false;
try
{
//if (simulate)
//{//模拟服务器返回
// operation.status = 200;
// operation.data.Clear();
// operation.data.Add("posId", "A001");
// string pos = "D100-111#D102-222#D104-333";
// operation.data.Add("pos", pos);
// if (operation.op == 1 || operation.op == 2)
// {//入库或出库
// string json = JsonHelper.SerializeObject(operation);
// LogUtil.error(LOGGER, "模拟HTTP服务器返回出库入库信息:" + json);
// return operation;
// }
//}
//else
//{
{
string json = "";
try
{
......@@ -52,7 +35,9 @@ namespace OnlineStore.Common
LogUtil.error("JsonHelper.SerializeObject(operation) 出错【operation.op=" + operation.op + "】" + ex);
}
string result = Post(url, json, Encoding.UTF8, out isTimeOut);
string result = PostJson(url, json, Encoding.UTF8, out isTimeOut);
if (!string.IsNullOrEmpty(result))
{
try
......@@ -63,8 +48,7 @@ namespace OnlineStore.Common
{
LogUtil.error("JsonHelper.DeserializeJsonToObject 出错【result=" + result + "】" + ex);
}
}
//}
}
}
catch (Exception ex)
{
......@@ -73,17 +57,14 @@ namespace OnlineStore.Common
return null;
}
private static int isLog = ConfigAppSettings.GetIntValue(Setting_Init.Server_Log_Open);
public static string Post(string url, string paramData, Encoding encoding, out bool IsTimeOut)
private static string PostJson(string url, string paramData, Encoding encoding, out bool IsTimeOut)
{
IsTimeOut = false;
if (isLog == 1)
{
LOGGER.Info("给服务器发送数据【" + paramData + "】 ");
}
if (paramData != "null" && paramData != null)
{
// LogUtil.debug(LOGGER, "HTTP POST to " + url + " \n\t >> " + paramData);
}
string result = "";
if (url.ToLower().IndexOf("https", System.StringComparison.Ordinal) > -1)
......@@ -99,8 +80,7 @@ namespace OnlineStore.Common
wc.Headers.Add("Content-Type", "application/json;charset=UTF-8");
wc.Encoding = encoding;
result = wc.UploadString(url, "POST", paramData);
//LogUtil.info(result);
result = wc.UploadString(url, "POST", paramData);
}
catch (WebException ex)
{
......@@ -110,6 +90,64 @@ namespace OnlineStore.Common
catch (Exception e)
{
LogUtil.error(LOGGER, "POST ERROR:" + e.ToString(), 1);
}
if (isLog == 1)
{
LogUtil.info("收到服务器数据【" + result + "】");
}
return result;
}
public static string Post(string url, string paramData, int timeOut = 5000)
{
bool IsTimeOut = false;
return Post(url, paramData, Encoding.UTF8, timeOut, out IsTimeOut);
}
public static string Post(string url, string paramData, Encoding encoding, int timeOut, out bool IsTimeOut)
{
if (paramData.Equals(""))
{
int index = url.IndexOf("?");
if (index > 0)
{
paramData = url.Substring(index + 1, url.Length - index - 1);
url = url.Substring(0, index);
}
}
IsTimeOut = false;
if (isLog == 1)
{
LogUtil.info("给服务器发送数据【" + url + "】【" + paramData + "】 ");
}
string result = "";
if (url.ToLower().IndexOf("https", System.StringComparison.Ordinal) > -1)
{
ServicePointManager.ServerCertificateValidationCallback =
new RemoteCertificateValidationCallback((sender, certificate, chain, errors) => { return true; });
}
try
{
var wc = new MyWebClient(timeOut);
if (string.IsNullOrEmpty(wc.Headers["Content-Type"]))
wc.Headers.Add("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
wc.Encoding = encoding;
result = wc.UploadString(url, "POST", paramData);
//LogUtil.info(result);
}
catch (WebException ex)
{
IsTimeOut = true;
LogUtil.error("POST [" + url + "] WebException :" + ex.ToString() );
}
catch (Exception e)
{
LogUtil.error("POST [" + url + "] ERROR:" + e.ToString() );
}
if (!result.Contains("null") && result.Length != 0)
{
......@@ -122,30 +160,5 @@ namespace OnlineStore.Common
return result;
}
//public static string Get(string url)
//{
// return Get(url, Encoding.UTF8);
//}
//public static string Get(string url, Encoding encoding)
//{
// try
// {
// LogUtil.info(LOGGER, "HTTP GET FROM: " + url);
// var wc = new WebClient { Encoding = encoding };
// var readStream = wc.OpenRead(url);
// using (var sr = new StreamReader(readStream, encoding))
// {
// var result = sr.ReadToEnd();
// LogUtil.info(LOGGER, "receive << " + result);
// return result;
// }
// }
// catch (Exception e)
// {
// LogUtil.error(LOGGER, "HTTP GET ERROR:" + e.Message, 2);
// }
// return "";
//}
}
}
\ No newline at end of file
......@@ -1287,7 +1287,7 @@ namespace OnlineStore.DeviceLibrary
for (int i = 1; i <= 3; i++)
{
bool timeOut = false;
Operation resultOperation = HttpHelper.Post(StoreManager.GetPostApi(server), operation, out timeOut);
Operation resultOperation = HttpHelper.PostOP(StoreManager.GetPostApi(server), operation, out timeOut);
if (timeOut)
{
LogUtil.info(LOGGER, logName + " 第" + i + "次发送超时 ");
......@@ -1655,7 +1655,7 @@ namespace OnlineStore.DeviceLibrary
}
string server = ConfigAppSettings.GetValue(Setting_Init.http_server);
bool isTimeout = false;
Operation resultOperation = HttpHelper.Post(StoreManager.GetPostApi(server), lineOperation, out isTimeout);
Operation resultOperation = HttpHelper.PostOP(StoreManager.GetPostApi(server), lineOperation, out isTimeout);
//发送状态信息到服务器
if (resultOperation == null || (resultOperation.op <= 0))
......
......@@ -68,8 +68,8 @@ namespace OnlineStore.DeviceLibrary
paramMap.Add("pos", StoreMove.MoveParam.PosInfo.PosId); // 库位
paramMap.Add("hasReel", reelIsExist.ToString()); // 是否有料
string server = StoreManager.GetAddr(StoreManager.Addr_posReelCheck, paramMap);
bool timeOut = false;
string resultStr = HttpHelper.Post(server, "", Encoding.UTF8, out timeOut);
//bool timeOut = false;
string resultStr = HttpHelper.Post(server, "" );
CheckPositionLog("盘点仓位: [CID=" + CID + "] [" + StoreMove.MoveParam.PosInfo.PosId + "] [IO_Type.reelIsExist=" + reelIsExist.ToString() + "] [resultStr=" + resultStr + "]");
reelIsExist = false;
}
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!