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();
}
}
}
物联网比赛代码笔记
最新推荐文章于 2023-02-08 15:05:46 发布