Beispiel #1
0
        /// <summary>
        /// MultipartForm请求
        /// </summary>
        /// <param name="postUrl">服务地址</param>
        /// <param name="userAgent"></param>
        /// <param name="postParameters">参数</param>
        /// <returns></returns>
        public static HttpWebResponse MultipartFormDataPost(string postUrl, string userAgent, Dictionary <string, object> postParameters)
        {
            string text        = string.Format("----------{0:N}", Guid.NewGuid());
            string contentType = "multipart/form-data; boundary=" + text;//multipart类型

            byte[] multipartFormData = HttpHelper4MultipartForm.GetMultipartFormData(postParameters, text);
            return(HttpHelper4MultipartForm.PostForm(postUrl, userAgent, contentType, multipartFormData));
        }
Beispiel #2
0
        public static string CheckYanzhi(Uri uri)
        {
            Dictionary <string, object> verifyPostParameters = new Dictionary <string, object>();

            verifyPostParameters.Add("api_key", "7Dx83WTIIEmIcabdcO293Lo97cYg4zcG");
            verifyPostParameters.Add("api_secret", "NgH2sfXe3Pb_95AjXJXv4kmAZFgdv8u4");
            verifyPostParameters.Add("return_landmark", "1");
            verifyPostParameters.Add("return_attributes", "gender,age,smiling,headpose,facequality,blur,eyestatus,emotion,ethnicity,beauty,mouthstatus,eyegaze,skinstatus");

            //添加图片参数
            verifyPostParameters.Add("image_url", uri.ToString());
            HttpWebResponse verifyResponse = HttpHelper4MultipartForm.MultipartFormDataPost("https://api-cn.faceplusplus.com/facepp/v3/detect", "", verifyPostParameters);
            var             resStream      = verifyResponse.GetResponseStream();
            var             streamReader   = new StreamReader(resStream);

            return(streamReader.ReadToEnd());
        }
Beispiel #3
0
        public static void CheckYanzhi(Stream imgStream)
        {
            Dictionary <string, object> verifyPostParameters = new Dictionary <string, object>();

            verifyPostParameters.Add("api_key", "7Dx83WTIIEmIcabdcO293Lo97cYg4zcG");
            verifyPostParameters.Add("api_secret", "NgH2sfXe3Pb_95AjXJXv4kmAZFgdv8u4");
            verifyPostParameters.Add("return_landmark", "1");
            verifyPostParameters.Add("return_attributes", "gender,age,smiling,headpose,facequality,blur,eyestatus,emotion,ethnicity,beauty,mouthstatus,eyegaze,skinstatus");
            //Bitmap bmp = new Bitmap("/tmp/1.jpg"); // 图片地址
            byte[] fileImage = new byte[imgStream.Length];
            //using (Stream stream1 = new MemoryStream())
            //{
            //    bmp.Save(stream1, ImageFormat.Jpeg);
            //    byte[] arr = new byte[stream1.Length];
            //    stream1.Position = 0;
            //    stream1.Read(arr, 0, (int)stream1.Length);
            //    stream1.Close();
            //    fileImage = arr;
            //}
            imgStream.ReadAsync(fileImage, 0, (int)imgStream.Length);
            //添加图片参数
            verifyPostParameters.Add("image_file", new HttpHelper4MultipartForm.FileParameter(fileImage, "1.jpg", "application/octet-stream"));
            HttpWebResponse verifyResponse = HttpHelper4MultipartForm.MultipartFormDataPost("https://api-cn.faceplusplus.com/facepp/v3/detect", "", verifyPostParameters);
        }