Commit 8feba3d1 LN

http修改

1 个父辈 37cce6d8
...@@ -95,6 +95,7 @@ namespace OnlineStore.ACSingleStore ...@@ -95,6 +95,7 @@ namespace OnlineStore.ACSingleStore
{ {
log4net.GlobalContext.Properties["fname"] = ConfigAppSettings.GetValue(Setting_Init.Store_CID); log4net.GlobalContext.Properties["fname"] = ConfigAppSettings.GetValue(Setting_Init.Store_CID);
log4net.Config.XmlConfigurator.Configure(); log4net.Config.XmlConfigurator.Configure();
System.Net.ServicePointManager.DefaultConnectionLimit = 512;
// XmlConfigurator.Configure(); // XmlConfigurator.Configure();
Application.EnableVisualStyles(); Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false); Application.SetCompatibleTextRenderingDefault(false);
......
...@@ -20,28 +20,11 @@ namespace OnlineStore.Common ...@@ -20,28 +20,11 @@ namespace OnlineStore.Common
{ {
public static readonly ILog LOGGER = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 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; isTimeOut = false;
try 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 = ""; string json = "";
try try
{ {
...@@ -52,7 +35,9 @@ namespace OnlineStore.Common ...@@ -52,7 +35,9 @@ namespace OnlineStore.Common
LogUtil.error("JsonHelper.SerializeObject(operation) 出错【operation.op=" + operation.op + "】" + ex); 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)) if (!string.IsNullOrEmpty(result))
{ {
try try
...@@ -64,7 +49,6 @@ namespace OnlineStore.Common ...@@ -64,7 +49,6 @@ namespace OnlineStore.Common
LogUtil.error("JsonHelper.DeserializeJsonToObject 出错【result=" + result + "】" + ex); LogUtil.error("JsonHelper.DeserializeJsonToObject 出错【result=" + result + "】" + ex);
} }
} }
//}
} }
catch (Exception ex) catch (Exception ex)
{ {
...@@ -73,17 +57,14 @@ namespace OnlineStore.Common ...@@ -73,17 +57,14 @@ namespace OnlineStore.Common
return null; return null;
} }
private static int isLog = ConfigAppSettings.GetIntValue(Setting_Init.Server_Log_Open); 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; IsTimeOut = false;
if (isLog == 1) if (isLog == 1)
{ {
LOGGER.Info("给服务器发送数据【" + paramData + "】 "); LOGGER.Info("给服务器发送数据【" + paramData + "】 ");
} }
if (paramData != "null" && paramData != null)
{
// LogUtil.debug(LOGGER, "HTTP POST to " + url + " \n\t >> " + paramData);
}
string result = ""; string result = "";
if (url.ToLower().IndexOf("https", System.StringComparison.Ordinal) > -1) if (url.ToLower().IndexOf("https", System.StringComparison.Ordinal) > -1)
...@@ -100,7 +81,6 @@ namespace OnlineStore.Common ...@@ -100,7 +81,6 @@ namespace OnlineStore.Common
wc.Encoding = encoding; wc.Encoding = encoding;
result = wc.UploadString(url, "POST", paramData); result = wc.UploadString(url, "POST", paramData);
//LogUtil.info(result);
} }
catch (WebException ex) catch (WebException ex)
{ {
...@@ -111,6 +91,64 @@ namespace OnlineStore.Common ...@@ -111,6 +91,64 @@ namespace OnlineStore.Common
{ {
LogUtil.error(LOGGER, "POST ERROR:" + e.ToString(), 1); 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) if (!result.Contains("null") && result.Length != 0)
{ {
//LogUtil.debug(LOGGER,"receive << " + result); //LogUtil.debug(LOGGER,"receive << " + result);
...@@ -122,30 +160,5 @@ namespace OnlineStore.Common ...@@ -122,30 +160,5 @@ namespace OnlineStore.Common
return result; 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 \ No newline at end of file
...@@ -1287,7 +1287,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -1287,7 +1287,7 @@ namespace OnlineStore.DeviceLibrary
for (int i = 1; i <= 3; i++) for (int i = 1; i <= 3; i++)
{ {
bool timeOut = false; 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) if (timeOut)
{ {
LogUtil.info(LOGGER, logName + " 第" + i + "次发送超时 "); LogUtil.info(LOGGER, logName + " 第" + i + "次发送超时 ");
...@@ -1655,7 +1655,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -1655,7 +1655,7 @@ namespace OnlineStore.DeviceLibrary
} }
string server = ConfigAppSettings.GetValue(Setting_Init.http_server); string server = ConfigAppSettings.GetValue(Setting_Init.http_server);
bool isTimeout = false; 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)) if (resultOperation == null || (resultOperation.op <= 0))
......
...@@ -68,8 +68,8 @@ namespace OnlineStore.DeviceLibrary ...@@ -68,8 +68,8 @@ namespace OnlineStore.DeviceLibrary
paramMap.Add("pos", StoreMove.MoveParam.PosInfo.PosId); // 库位 paramMap.Add("pos", StoreMove.MoveParam.PosInfo.PosId); // 库位
paramMap.Add("hasReel", reelIsExist.ToString()); // 是否有料 paramMap.Add("hasReel", reelIsExist.ToString()); // 是否有料
string server = StoreManager.GetAddr(StoreManager.Addr_posReelCheck, paramMap); string server = StoreManager.GetAddr(StoreManager.Addr_posReelCheck, paramMap);
bool timeOut = false; //bool timeOut = false;
string resultStr = HttpHelper.Post(server, "", Encoding.UTF8, out timeOut); string resultStr = HttpHelper.Post(server, "" );
CheckPositionLog("盘点仓位: [CID=" + CID + "] [" + StoreMove.MoveParam.PosInfo.PosId + "] [IO_Type.reelIsExist=" + reelIsExist.ToString() + "] [resultStr=" + resultStr + "]"); CheckPositionLog("盘点仓位: [CID=" + CID + "] [" + StoreMove.MoveParam.PosInfo.PosId + "] [IO_Type.reelIsExist=" + reelIsExist.ToString() + "] [resultStr=" + resultStr + "]");
reelIsExist = false; reelIsExist = false;
} }
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!