private void button3_Click(object sender, EventArgs e) { DataAcquisitionResult result = new DataAcquisitionResult(); List <EquipmentListOneDTO> dtos = new List <EquipmentListOneDTO>(); EquipmentListOneDTO dto = new EquipmentListOneDTO(); dto.equipmentname = "CNC01"; dto.moldno = "JD1"; dto.workpiecesname = "JDM-007"; dto.colour = "red"; dtos.Add(dto); dto = new EquipmentListOneDTO(); dto.equipmentname = "CNC02"; dto.moldno = "JD2"; dto.workpiecesname = "JDM-008"; dto.colour = "yellow"; dtos.Add(dto); string server = "http://localhost:15988/api/TeamTask/SaveEquipmentMachining"; EquipmentListAPIParameterA param = new EquipmentListAPIParameterA(); param.operator_name = "WebApi"; param.operator_time = GenerateTimeStamp(DateTime.Now); param.sign = GenSign(param.operator_name, param.operator_time); param.data = dtos; Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("operator_name", param.operator_name); dic.Add("operator_time", param.operator_time); dic.Add("sign", param.sign); dic.Add("strdata", Serialize(param.data)); try { HttpWebResponse response = CreatePostHttpResponse(server, dic, null, null, Encoding.UTF8, null); System.IO.StreamReader sr = new System.IO.StreamReader(response.GetResponseStream()); string responseContent = sr.ReadToEnd(); sr.Close(); DataAcquisitionResult rtn = Deserialize <DataAcquisitionResult>(responseContent); if (rtn.code != "1000") { return; } } catch (Exception ex) { return; } }
public DataAcquisitionResult SaveEquipmentMachining([FromBody] EquipmentListAPIParameterA param) { //记时 LogHelper.Info("SaveEquipmentMachining--开始"); Stopwatch timeWatcher = new Stopwatch(); long checkTime = 0; timeWatcher.Restart(); //开始计时 DataAcquisitionResult result = new DataAcquisitionResult(); result.code = "1000"; result.msg = "success"; if (param == null) { param = new EquipmentListAPIParameterA(); this.Request.GetQueryNameValuePairs(); HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"]; //获取传统context HttpRequestBase request = context.Request; //定义传统request对象 param.operator_name = request.Form["operator_name"]; param.operator_time = request.Form["operator_time"]; param.sign = request.Form["sign"]; param.strdata = request.Form["strdata"]; LogHelper.Info("WebApi-SaveEquipmentMachining param from forms"); } if (!VerifyMiddleSign(param.operator_name, param.operator_time, param.sign)) { LogHelper.Info(string.Format("operator_name{0},operation_time{1},sign{2}", param.operator_name, param.operator_time, param.sign)); result.msg = "签名错误"; result.code = "1040"; return(result); } List <EquipmentListOneDTO> dto = new List <EquipmentListOneDTO>(); try { dto = Deserialize <List <EquipmentListOneDTO> >(param.strdata); foreach (var item in dto) { bool fla = UpdateEquipmentListOne(item); if (!fla) { LogHelper.Error(string.Format("更新失败-SaveEquipmentMachining:{0}", Serialize(item))); //result.msg = "数据更新失败"; //result.code = "1050"; //return result; } } } catch (Exception ex) { LogHelper.Error(ex.Message); result.msg = ex.Message; result.code = "1060"; return(result); } timeWatcher.Stop();//结束计时 checkTime = timeWatcher.ElapsedMilliseconds; LogHelper.Info(string.Format("SaveEquipmentMachining--结束,执行时间:{0} ", checkTime)); return(result); }