.NET对接TSINGSEE青犀视频智能分析平台API的部分功能及技巧总结(内含POST和GET的调用)
Posted TSINGSEE
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了.NET对接TSINGSEE青犀视频智能分析平台API的部分功能及技巧总结(内含POST和GET的调用)相关的知识,希望对你有一定的参考价值。
TSINGSEE青犀视频智能分析平台EasyNVR、EasyCVR等都具备丰富的API接口,API接口中密码需要MD5加密,这一点是为了系统安全考虑,下文中有具体实现,可以参考。本文我们总结下NET对接TSINGSEE青犀视频智能分析平台API用到的几个小功能,TSINGSEE青犀视频智能分析平台中API接口提供的POST和GET的调用下文中也有具体实现,请注意下,我们反复强调接口调用的时候请注意下TOKEN值的传递。
1、Easy系列产品在登录时对密码需要进行32位MD5加密,.NET对应实现如下:
public string GetMd5(string str)
{
MD5 md5 = new MD5CryptoServiceProvider();
byte[] bytes = System.Text.Encoding.UTF8.GetBytes(str);
bytes = md5.ComputeHash(bytes);
md5.Clear();
string ret = "";
for (int i = 0; i < bytes.Length; i++)
{
ret += Convert.ToString(bytes[i], 16).PadLeft(2, '0');
}
return ret.PadLeft(32, '0');
}
2、向指定URL发送HTTP -GET方法的请求
public string SendGet(string url, string param)
{
string result = String.Empty;
StreamReader reader = null;
try
{
string urlNameString = url + "?" + param;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(urlNameString);
request.Method = "GET";
request.ContentType = "text/html;charset=UTF-8";
request.Accept = "*/*";
request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)";
//头里面要带入token
request.Headers.Add("Cookie", "token=acMyRwXZg");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream responseStream = response.GetResponseStream();
reader = new StreamReader(responseStream, Encoding.GetEncoding("utf-8"));
result = reader.ReadToEnd();
reader.Close();
responseStream.Close();
response.Close();
reader = null;
responseStream = null;
response = null;
}
catch (Exception ex)
{
Console.WriteLine("发送GET请求出现异常:" + ex.Message);
}
finally
{
if (reader != null)
{
reader.Close();
}
}
return result;
}
3、向指定 URL 发送HTTP-POST方法的请求
public string SendPost(string url, string jsonData, string encoding)
{
string result = String.Empty;
try
{
CookieContainer cookie = new CookieContainer();
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "POST";
request.Headers.Add("x-requested-with", "XMLHttpRequest");
request.ServicePoint.Expect100Continue = false;
request.ContentType = "application/x-www-form-urlencoded";
request.Accept = "*/*";
request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)";
request.ContentLength = Encoding.UTF8.GetByteCount(jsonData);
request.CookieContainer = cookie;
using (StreamWriter writer = new StreamWriter(request.GetRequestStream(), Encoding.GetEncoding(encoding)))
{
writer.Write(jsonData);
}
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
response.Cookies = cookie.GetCookies(response.ResponseUri);
using (Stream responseStream = response.GetResponseStream())
{
using (StreamReader reader = new StreamReader(responseStream, Encoding.GetEncoding(encoding)))
{
result = reader.ReadToEnd();
reader.Close();
}
responseStream.Close();
}
response.Close();
response = null;
request = null;
}
catch (Exception ex)
{
Console.WriteLine("发送GET请求出现异常:" + ex.Message);
}
return result;
}
以上是关于.NET对接TSINGSEE青犀视频智能分析平台API的部分功能及技巧总结(内含POST和GET的调用)的主要内容,如果未能解决你的问题,请参考以下文章
AI技术不断重构安防,TSINGSEE青犀助力视频能力多场景智能化
TSINGSEE青犀视频利用GO集成百度AI人脸识别算法的开发实践
TSINGSEE青犀视频Easy系列视频平台如何快捷判断视频流编码格式?
TSINGSEE青犀视频开发Python3行人分析功能运行一段时间后崩溃是什么原因?