Dim bmp As new Bitmap("d:\Desktop\测试学校.jpg")
Dim ms As new System.Io.MemoryStream()
bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg)
Dim arr(ms.Length) As Byte '这里msgbox(arr(ms.Length)) 显示0
ms.Position = 0
ms.Read(arr, 0, ms.Length)
ms.Close()
Dim strbase64 As String = Convert.ToBase64String(arr) 'msgbox(strbase64)无反应,是arr有问题么?
Dim urlencode As String = System.Web.HttpUtility.UrlEncode(strbase64)
bmp.dispose
msgbox("读取图片完毕")
Dim body As String = "{""image"":""" & urlencode & """}" '这里的参数是urlencode 还是strbase64?
Dim token As String = "24.0b33955496d861eb8446d40ae671bfd4.2592000.1553022364.281335-15584661"
Dim req = System.Net.WebRequest.Create("https://aip.baidubce.com/rest/2.0/solution/v1/form_ocr/request?access_token=" & token)
req.Method = "POST"
req.C
Dim aryBuf As Byte() = Encoding.UTF8.GetBytes(body)
req.ContentLength = aryBuf.Length
Dim writer = req.GetRequestStream()
writer.Write(aryBuf, 0, aryBuf.Length)
writer.Close()
writer.Dispose()
Dim pos = req.GetResponse
msgbox("获取数据完毕")
Dim stm As System.IO.Stream = pos.GetResponseStream()
Dim reader As New System.IO.StreamReader(stm)
Dim str As String = reader.ReadToEnd
pos.Close
stm.Close
reader.close
Dim jo As JObject = Jobject.Parse(str)
msgbox(jo.ToString)