示例#1
0
        public string General(Image image)
        {
            //string token = "#####调用鉴权接口获取的token#####";
            string         strbaser64 = FileOperate.GetFileBase64(image); // 图片的base64编码
            string         host       = "https://aip.baidubce.com/rest/2.0/ocr/v1/general?access_token=" + ModelFactory.TOKEN;
            Encoding       encoding   = Encoding.Default;
            HttpWebRequest request    = (HttpWebRequest)WebRequest.Create(host);

            request.Method      = "post";
            request.ContentType = "application/x-www-form-urlencoded";
            request.KeepAlive   = true;
            String str = "image=" + HttpUtility.UrlEncode(strbaser64);

            byte[] buffer = encoding.GetBytes(str);
            request.ContentLength = buffer.Length;
            request.GetRequestStream().Write(buffer, 0, buffer.Length);
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            StreamReader    reader   = new StreamReader(response.GetResponseStream(), Encoding.Default);
            string          result   = reader.ReadToEnd();

            Console.WriteLine("通用文字识别:");
            Console.WriteLine(result);
            return(result);
        }