C# http post请求

try
                {

                    string url = "http://192.168.127.245:8099/api/AlarmInfo/AlarmInfoGET?count=100";
                    System.Net.HttpWebResponse response = HttpWebResponseUtility.CreateGetHttpResponse(url);
                    string strValue = "";
                    System.IO.Stream s;
                    s = response.GetResponseStream();
                    string StrDate = "";

                    StreamReader Reader = new StreamReader(s, Encoding.UTF8);
                    while ((StrDate = Reader.ReadLine()) != null)
                    {
                        strValue += StrDate;
                        //strValue += StrDate + "\r\n";
                    }
                    List<AlarmInfo> model = JSONStringToList<AlarmInfo>(strValue);
                    //model = model.OrderBy(u => u.UpdateTime).ToList(); //这样我们也把他进行了一次排序
                    //model.Sort((AlarmInfo p1, AlarmInfo p2) => p1.UpdateTime.CompareTo(p2.UpdateTime));
                    model.Sort((AlarmInfo p1, AlarmInfo p2) => p2.UpdateTime.CompareTo(p1.UpdateTime)); //排序

                    model = model.Take(30).ToList(); //获取前30条数据


                    List<AlarmInfoMode> alarmInfoModes = new List<AlarmInfoMode>();
                    foreach (AlarmInfo item in model)
                    {
                        AlarmInfoMode alarmInfoMode = new AlarmInfoMode() {
                            _AlarmStations = GetAlarmStations(item.AssemblyLineId),
                            Id=item.Id,
                            UpdateTime=item.UpdateTime,
                            AlarmContent=item.AlarmContent,
                            IPAddress=item.IPAddress
                        };
                        alarmInfoModes.Add(alarmInfoMode);
                    }
                    this._DataGrid.Dispatcher.BeginInvoke(DispatcherPriority.Background, (Action)(() => //委托异步执行
                    {
                        this._DataGrid.ItemsSource = alarmInfoModes;
                    }));
                }
                catch (Exception err)
                {
                    Logger.Error(err);
                }

参考网址【.net core请求外部api接口_香煎三文鱼的博客-CSDN博客

参考网址【C# 中 WebClient HttpClient 的区别

.net core请求多个api【.NET CORE后台请求API_雨中深巷的油纸伞的博客-CSDN博客

net core后台接收 Form ajax post get请求参数_Better_Roy的博客-CSDN博客

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值