源码如下:
?using System;
using System.IO;
using System.Net;
using System.Text;
using System.Web;
namespace
com.baidu.ai
{
public
class
General
{
public
static
string
general()
{
string token = "#####调用鉴权接口获取的token#####";
string strbaser64 = FileUtils.getFileBase64("/work/ai/images/ocr/general.jpeg");
string host = "https://aip.baidubce.com/rest/2.0/ocr/v1/general?access_token=" + 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;
}
}
}
拜托各位,谢谢!