用于上传图片base64位
private void upLoadCunzai()
{
errorstring += " upLoadCunzai方法执行成功:用于上传已经存在人员摄像头照片到服务器";
LogString += errorstring;
NiuLog.rizhi("程序运行过程信息", errorstring);
//创建WebClient 对象
WebClient web = new WebClient();
//读取拍摄照片存放的路径
byte[] WriteData = File.ReadAllBytes(sfzzpbflist);
//上传base64位图片必须加上Replace("+", "%2B"),否则url信息会出错
String strbaser64 = Convert.ToBase64String(WriteData).Replace("+", "%2B");
//Console.Write("转换后的数据:" + strbaser64);
//需要发送的数据信息,人员编号、设备编号、图片64位
string postString = "token=WY5Av6lYRHzvxyIGYGxT56PVek9eYSoN&personNumber=" + bianhao + "&deviceNumber=AC0018077460&faceImage=" + strbaser64;
//采取POST方式必须加的header,如果改为GET方式的话就去掉这句话即可
web.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
//转化为二进制数据
byte[] postData = Encoding.UTF8.GetBytes(postString);
//上传数据
byte[] responseData = web.UploadData(path, "POST", postData);
//Console.Write("服务器路径:" + path);
//服务器返回的数据
string huifu = Encoding.UTF8.GetString(responseData);
Console.Write("上传已存在人员服务器返回的数据:" + huifu);
}
用于查询信息
private string query()
{
//创建WebClient 对象
WebClient web = new WebClient();
//需要上传的数据
string postString = "token=WY5Av6lYRHzvxyIGYGxT56PVek9eYSoN&startTime=2019-04-01&endTime=2019-06-01&startIndex=0&length=50";
//以form表单的形式上传
web.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
// 转化成二进制数组
byte[] postData = Encoding.ASCII.GetBytes(postString);
// 上传数据
byte[] responseData = web.UploadData(pathQuery, "POST", postData);
//Console.Write("服务器路径:" + pathQuery);
//获取返回的二进制数据.
string huifu = Encoding.UTF8.GetString(responseData);
Console.Write("查询服务器返回的数据:" + huifu+"\r\n");
return huifu;
}