using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace TrainVideoDataDispose
{
public partial class text : Form
{
public text()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string datas = "searchC9C75F94-1CA0-0001-BF8B-131E7EE0C9A02022-04-09T00:00:00Z2022-04-09T23:59:59Z00true020";
Hashtable hashtable = new Hashtable();
hashtable.Add("Authorization", "Digest username=\"admin\", realm=\"DVRNVRDVS\", nonce=\"d632db908d1b779b748f21029bf170a2: 1649501141033\", uri=\"/ISAPI/Traffic/ContentMgmt/dataOperation\", algorithm=MD5, response=\"04f92810633b6941fe491cc1235a12b5\", qop=auth, nc=00000092, cnonce=\"0d74d34eee63862e\"");
string result = Http("http://10.111.67.23/ISAPI/Traffic/ContentMgmt/dataOperation", "POST", "application/json;charset=utf-8", hashtable, datas);
}
///
/// 不做catch处理,需要在外部做
///
///
/// 默认GET,空则补充为GET
/// 默认json,空则补充为json
/// 请求头部
/// 请求body内容
///
public static string Http(string url, string method = "GET", string contenttype = "application/json;charset=utf-8", Hashtable header = null, string data = null)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = string.IsNullOrEmpty(method) ? "GET" : method;
request.ContentType = string.IsNullOrEmpty(contenttype) ? "application/json;charset=utf-8" : contenttype;
if (header != null)
{
foreach (var i in header.Keys)
{
request.Headers.Add(i.ToString(), header[i].ToString());
}
}
if (!string.IsNullOrEmpty(data))
{
Stream RequestStream = request.GetRequestStream();
byte[] bytes = Encoding.UTF8.GetBytes(data);
RequestStream.Write(bytes, 0, bytes.Length);
RequestStream.Close();
}
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream ResponseStream = response.GetResponseStream();
StreamReader StreamReader = new StreamReader(ResponseStream, Encoding.GetEncoding("utf-8"));
string re = StreamReader.ReadToEnd();
StreamReader.Close();
ResponseStream.Close();
return re;
}
}
}