以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  请求参数如果合成?  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=131348)

--  作者:133198609
--  发布时间:2019/2/23 22:49:00
--  请求参数如果合成?

图片点击可在新窗口打开查看此主题相关图片如下:微信图片_20190223224631.png
图片点击可在新窗口打开查看

这种参数该如何合成?以下代码提示image参数错误

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)


[此贴子已经被作者于2019/2/24 0:54:32编辑过]

--  作者:有点甜
--  发布时间:2019/2/24 13:18:00
--  

读取图片这样处理

 

Dim ms As New IO.FileStream("d:\\test.jpg", IO.FileMode.Open)
msgbox(ms.length)
Dim arr(ms.length) As Byte
Dim count = ms.read(arr, 0, arr.length)
ms.Close()
msgbox("读取图片完毕")