#region form-data格式 //start 将实体Contract转换成所需的小驼峰格式(例如:helloWord) Contract contract=new Contract(); contract.ContractName="合同1"; contract.ContractType="其他合同"; var setting = new JsonSerializerSettings { ContractResolver = new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver() }; var json = JsonConvert.SerializeObject(contract, setting); //end List<KeyValuePair<String, String>> paramList = new List<KeyValuePair<String, String>> { new KeyValuePair<string, string>("archivesElement", json), new KeyValuePair<string, string>("dataId", "111111"), new KeyValuePair<string, string>("dataCreator", "admin") }; FormUrlEncodedContent formUrlEncodedContent= new FormUrlEncodedContent(paramList); formUrlEncodedContent.Headers.Add("consumerCode", consumerCode); formUrlEncodedContent.Headers.Add("operationCode", operationCode); var res = client.PostAsync(new Uri(url), formUrlEncodedContent).Result; Dictionary<string, object> dic = JsonConvert.DeserializeObject<Dictionary<string, object>>(res.Content.ReadAsStringAsync().Result); Log log = new Log(); if (dic["code"].ToString()=="100000") { log.SuccesTime = DateTime.Now; log.PushState = 1; log.PushMsg = dic["message"].ToString(); } else { log.SuccesTime = DateTime.Now; log.PushState = 2; log.PushMsg = dic["message"].ToString(); } #endregion
#region form-data格式 //start 将实体Contract转换成所需的小驼峰格式(例如:helloWord) Contract contract=new Contract(); contract.ContractName="合同1"; contract.ContractType="其他合同"; var setting = new JsonSerializerSettings { ContractResolver = new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver() }; var json = JsonConvert.SerializeObject(contract, setting); var retrunValue = Newtonsoft.Json.JsonConvert.DeserializeObject<dynamic>(json.ToString()); //end HttpContent content = new StringContent(retrunValue.ToString()); content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json"); content.Headers.Add("consumerCode", consumerCode); content.Headers.Add("operationCode", operationCode); var res = client.PostAsync(new Uri(url), content).Result; Dictionary<string, object> dic = JsonConvert.DeserializeObject<Dictionary<string, object>>(res.Content.ReadAsStringAsync().Result); Log log = new Log(); if (dic["code"].ToString()=="100000") { log.SuccesTime = DateTime.Now; log.PushState = 1; log.PushMsg = dic["message"].ToString(); } else { log.SuccesTime = DateTime.Now; log.PushState = 2; log.PushMsg = dic["message"].ToString(); }
//start 将实体Contract转换成所需的小驼峰格式(例如:helloWord) Contract contract=new Contract(); contract.ContractName="合同1"; contract.ContractType="其他合同" var setting = new JsonSerializerSettings { ContractResolver = new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver() }; var json = JsonConvert.SerializeObject(contract, setting); var retrunValue = Newtonsoft.Json.JsonConvert.DeserializeObject<dynamic>(json.ToString()); //end