Foxtable(狐表)用户栏目专家坐堂 → 请求参数如果合成?


  共有2235人关注过本帖树形打印复制链接

主题:请求参数如果合成?

帅哥哟,离线,有人找我吗?
133198609
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:小狐 帖子:373 积分:3107 威望:0 精华:0 注册:2015/1/30 9:47:00
请求参数如果合成?  发帖心情 Post By: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编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By: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("读取图片完毕")


 回到顶部