物联网比赛代码笔记

using System.Linq;
using System.Text;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

using System.Net.Http;//导入 .net HTTP协议
using Newtonsoft.Json;//导入json
using System.Windows.Threading;//导入线程包
namespace WpfApp5
{
    public partial class yjd : Window
    {
        private HttpClient httpClient; //客户端

        private HttpClientHandler handler = new HttpClientHandler();//处理器
        private DispatcherTimer dispatcherTimer = new DispatcherTimer();//生成一给定时器
        public string url = "http://iot.whwzzc.com:8088/wziot/wzIotApi/";
        public string projectId = "18d9a048-807a-4362-bc55-4048d906bbfe";
        private string str = "268559945";
        public yjd()
        {
            InitializeComponent();//初始化组件
            //handler = new HttpClientHandler();
            handler.AllowAutoRedirect = false;//不允许自动重定向
            httpClient = new HttpClient(handler);//创建一个新客户端
            //httpClient.MaxResponseContentBufferSize = 256000;
            httpClient.MaxResponseContentBufferSize = 200000;//缓冲区大小
        } 

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            var task = httpClient.GetAsync(url + "controlSensorByKey/" + projectId + "/" + str.ToString() + "?uuid=30012&key=1");
             //获取异步
            task.Result.EnsureSuccessStatusCode();
            //结果。确保成功状态码
        }

        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            var task = httpClient.GetAsync(url + "controlSensorByKey/" + projectId + "/" + str.ToString() + "?uuid=30012&key=2");
            task.Result.EnsureSuccessStatusCode();
        }
    }
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值