C# 发送http方法,利用键值对 KeyValuePair,发送分页命令,日历的开始和结束时间命令(POST)
2021-02-17 14:16
一个HTTP的类里面:
public static string HttpClientPost(string url, string taskIdx, string taskidxvalue, string source_ID, string source_ID_value, string StartTime, string StartTimeValue, string endTime, string endTimeValue, string startNum, string startNumValue, string pageSize, string pageSizeValue)
{
string resultContent = "";
try
{
using (var client = new HttpClient())
{
client.BaseAddress = new Uri(url);
var content = new FormUrlEncodedContent(new[]
{
new KeyValuePair
new KeyValuePair
new KeyValuePair
new KeyValuePair
new KeyValuePair
new KeyValuePair
});
var result = client.PostAsync(url, content).Result;
resultContent = result.Content.ReadAsStringAsync().Result;
}
}
catch (Exception ex)
{
}
return resultContent;
}
.cs调用:
(包括分页,日历的开始和结束时间)
public CompareNew_Json GetHttpJsonToOb(string url, string taskIdx = "", string taskidxvalue = "", string source_ID = "", string source_ID_value = "", string StartTime = "", string StartTimeValue = "", string endTime = "", string endTimeValue = "", string startNum = "", string startNumValue = "", string pageSize = "", string pageSizeValue = "")
{
CompareNew_Json rt = null;
string resultContent = HttpRequest.HttpClientPost(url, taskIdx, taskidxvalue, source_ID, source_ID_value, StartTime, StartTimeValue, endTime, endTimeValue, startNum, startNumValue, pageSize, pageSizeValue);
if (resultContent != "")
{
rt = JsonConvert.DeserializeObject
MessageBox.Show(rt.alarmCount.ToString());
if (rt.alarmCount % 32 == 0)
{
pageSum = rt.alarmCount / 32;
tb_sumnum.Content = pageSum;
}
else
{
pageSum = (rt.alarmCount / 32) + 1;
tb_sumnum.Content = pageSum;
}
resultContent = "";
}
return rt;
}
调用上面的方法:
public void SaySomething(string starttime = "", string endtime = "")
{
string _starttime = "";
string _endtime = "";
if (starttime != "" && endtime != "")
{
_starttime = "StartTime";
_endtime = "endTime";
}
Dispatcher.Invoke(() => {
CompareNew_Json json = GetHttpJsonToOb("http://192.168.20.66:8080/SSMFace05/history/alarm/getDynamic", StartTime: _starttime, StartTimeValue: starttime, endTime: _endtime, endTimeValue: endtime, startNum: "startNum", startNumValue: pagenum.ToString(), pageSize: "pageSize", pageSizeValue: "32");
DataAnalysisdataGrid = new List
tb_num.Content = pagenum;
if (json.alarms != null)
{
for (int i = 0; i {
DataGridBindingData dgd = new DataGridBindingData();
dgd.dataID = i.ToString();
dgd.Time = json.alarms[i].alarmTime;
dgd.VideoSource = json.alarms[i].source.sourceName;
dgd.goalpeople = json.alarms[i].target.targetName;
dgd.CallTimes = ((json.alarms[i].alarmSimilar) * 100).ToString() + "%";
DataAnalysisdataGrid.Add(dgd);
}
}
dataGrid.ItemsSource = DataAnalysisdataGrid;
});
}
文章标题:C# 发送http方法,利用键值对 KeyValuePair,发送分页命令,日历的开始和结束时间命令(POST)
文章链接:http://soscw.com/index.php/essay/56597.html