首页 新闻 会员 周边 捐助

百度H5活体检测,Postman正确返回,代码调用返回没有找到人脸

0
[待解决问题]

同样的视频转换后的base64字符串 ,在postman中可以正确返回,在代码调用时返回no face
代码:

private void button1_Click(object sender, EventArgs e)
{
string url = "https://aip.baidubce.com/rest/2.0/face/v1/faceliveness/verify?access_token=24.27adb89a14ca87b37e7860c4de73e158.2592000.1555135729.282335-15747603";
string path =Application.StartupPath+"\base64.mp4";
FileStream filestream = new FileStream(path, FileMode.Open);
byte[] bt = new byte[filestream.Length];
//调用read读取方法
filestream.Read(bt, 0, bt.Length);
string base64Str = Convert.ToBase64String(bt);
filestream.Close();
PostWebRequest(url, "video_base64=" + base64Str);
}

    /// <summary>

        /// Post提交数据
        /// </summary>
        /// <param name="postUrl">URL</param>
        /// <param name="paramData">参数</param>
        /// <returns></returns>
        private string PostWebRequest(string postUrl, string paramData)
{
string ret = string.Empty;
try
{
if (!postUrl.StartsWith("http://") && !postUrl.StartsWith("https://"))
return "";

            byte[] byteArray = Encoding.Default.GetBytes(paramData); //转化 /

                HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(new Uri(postUrl));
webReq.Method = "POST";
webReq.ContentType = "application/x-www-form-urlencoded";
webReq.ContentLength = byteArray.Length;
Stream newStream = webReq.GetRequestStream();
newStream.Write(byteArray, 0, byteArray.Length);//写入参数
                newStream.Close();
HttpWebResponse response = (HttpWebResponse)webReq.GetResponse();
StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
ret = sr.ReadToEnd();
sr.Close();
response.Close();
newStream.Close();
}
catch (Exception ex)
{
return ex.Message;
}
return ret;
}

迷.的主页 迷. | 初学一级 | 园豆:4
提问于:2019-03-19 10:31
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册