香参照以下接口Demo说明,读取一个图片为二进制数据,并直接发送,在Foxtable中如何实现?
https://ai.intsig.com/doc/general/sample_code/v1.0
尤其这句话,不知如何实现
POST BODY:待识别的文件二进制流
System.IO.FileStream.Read读取到的内容是Byte()字节数组,可是Foxtable的HttpClient要传输的却是String,如果使用System.Text.Encoding.UTF8.GetString(Byte())或者System.Text.Encoding.ASCII.GetString(Byte())读取到的字符串与十六进制编辑器直接打开看到的数据不一致,因此直接给API结果传过去也会报错,该怎么处理呢?
有大神可以参照C#示例代码,写一个Foxtable版本的代码吗?
using System;
using System.Drawing;
using System.IO;
using System.Net;
namespace AiApi
{
class Program
{
static void Main(string[] args)
{
string appKey = "5c6b*****************f4d85"; // your app_key
string appSecret = "c83e******************6a9e"; // your app_secret
string url = "https://ocr-api.ccint.com/cci_ai/service/v1/id_card"; // id_card
var img = GetPictureData("example.jpg");
using (var client = new WebClient())
{
try
{
client.Headers.Add("app-key", appKey);
client.Headers.Add("app-secret", appSecret);
var response = client.UploadData(url, img);
string result= System.Text.Encoding.UTF8.GetString(response);
Console.WriteLine(result);
}
catch(WebException e)
{
Console.WriteLine(e.Status);
}
Console.ReadLine();
}
}
private static byte[] GetPictureData(string imagepath)
{
FileStream fs = new FileStream(imagepath, FileMode.Open);
byte[] byData = new byte[fs.Length];
fs.Read(byData, 0, byData.Length);
fs.Close();
return byData;
}
}
}
[此贴子已经被作者于2022/4/1 16:03:06编辑过]