|
- 按键工程师
- 742060
- 2281
- 5
- 881 朵
- 10799 个
- 580 个
- 48300
- 2011-08-18
|
1#
t
T
发表于 2021-11-26 18:49
|
|只看楼主
现在官方自带的http的命令少了个提交文件的功能,美中不足Ý%gÖòÄbbs.vrbrothers.comüôânög无可奈何我就被迫营业封装了一个http的插件,可以支持upload功能Ý%gÖòÄbbs.vrbrothers.comüôânögÝ%gÖòÄbbs.vrbrothers.comüôânög Ý%gÖòÄbbs.vrbrothers.comüôânög目前插件还是内测版本,功能不完善且概率存在一定BUG,后续会进行迭代更新Ý%gÖòÄbbs.vrbrothers.comüôânög Ý%gÖòÄbbs.vrbrothers.comüôânög
功能特色Ý%gÖòÄbbs.vrbrothers.comüôânög
- 自定义header消息头Ý%gÖòÄbbs.vrbrothers.comüôânög
- 智能判定Content-Type类型Ý%gÖòÄbbs.vrbrothers.comüôânög
- 支持Android&IOS双端使用Ý%gÖòÄbbs.vrbrothers.comüôânög
- 统一的payload格式传入(table类型)Ý%gÖòÄbbs.vrbrothers.comüôânög
Ý%gÖòÄbbs.vrbrothers.comüôânög Ý%gÖòÄbbs.vrbrothers.comüôânögÝ%gÖòÄbbs.vrbrothers.comüôânög Ý%gÖòÄbbs.vrbrothers.comüôânög命令功能Ý%gÖòÄbbs.vrbrothers.comüôânög Ý%gÖòÄbbs.vrbrothers.comüôânögSHTTP.Get(url, opts)Ý%gÖòÄbbs.vrbrothers.comüôânög
- 功能:发送Get请求Ý%gÖòÄbbs.vrbrothers.comüôânög
- 参数:Ý%gÖòÄbbs.vrbrothers.comüôânög
Ý%gÖòÄbbs.vrbrothers.comüôânög
- url: 必选,请求的urlÝ%gÖòÄbbs.vrbrothers.comüôânög
- opts: 可选参数,包含以下参数的键值表headers: 自定义http消息头,可以是键值表或者字符串timeout: 请求超时时间,默认为10秒files: 上传文件路径Ý%gÖòÄbbs.vrbrothers.comüôânög
- 返回:返回请求结果Ý%gÖòÄbbs.vrbrothers.comüôânög
Ý%gÖòÄbbs.vrbrothers.comüôânög Ý%gÖòÄbbs.vrbrothers.comüôânögÝ%gÖòÄbbs.vrbrothers.comüôânög Ý%gÖòÄbbs.vrbrothers.comüôânögSHTTP.Post(url, data, opts)Ý%gÖòÄbbs.vrbrothers.comüôânög
- 功能:发送Get请求Ý%gÖòÄbbs.vrbrothers.comüôânög
- 参数:Ý%gÖòÄbbs.vrbrothers.comüôânög
Ý%gÖòÄbbs.vrbrothers.comüôânög
- url: 必选,请求的urlÝ%gÖòÄbbs.vrbrothers.comüôânög
- data: 必选,需要提交的请求数据,用键值表或者key-value存放提交数据Ý%gÖòÄbbs.vrbrothers.comüôânög
- opts: 可选参数,包含以下参数的键值表headers: 自定义http消息头,可以是键值表或者字符串timeout: 请求超时时间,默认为10秒files: 上传文件路径Ý%gÖòÄbbs.vrbrothers.comüôânög
- 返回:返回请求结果Ý%gÖòÄbbs.vrbrothers.comüôânög
Ý%gÖòÄbbs.vrbrothers.comüôânög Ý%gÖòÄbbs.vrbrothers.comüôânögÝ%gÖòÄbbs.vrbrothers.comüôânög Ý%gÖòÄbbs.vrbrothers.comüôânög使用范例Ý%gÖòÄbbs.vrbrothers.comüôânög Ý%gÖòÄbbs.vrbrothers.comüôânög简单的Get网页- Import "SHTTP.lua"Ý%gÖòÄbbs.vrbrothers.comüôânög
Ý%gÖòÄbbs.vrbrothers.comüôânögÝ%gÖòÄbbs.vrbrothers.comüôânög
Ý%gÖòÄbbs.vrbrothers.comüôânög
- TracePrint SHTTP.Get("http://bbs.anjian.com/")Ý%gÖòÄbbs.vrbrothers.comüôânög
Ý%gÖòÄbbs.vrbrothers.comüôânögÝ%gÖòÄbbs.vrbrothers.comüôânög
Ý%gÖòÄbbs.vrbrothers.comüôânög
复制代码 附带请求头Get- Import "SHTTP.lua"Ý%gÖòÄbbs.vrbrothers.comüôânög
Ý%gÖòÄbbs.vrbrothers.comüôânögÝ%gÖòÄbbs.vrbrothers.comüôânög
Ý%gÖòÄbbs.vrbrothers.comüôânög
- Ý%gÖòÄbbs.vrbrothers.comüôânög
Ý%gÖòÄbbs.vrbrothers.comüôânögÝ%gÖòÄbbs.vrbrothers.comüôânög
Ý%gÖòÄbbs.vrbrothers.comüôânög
- Dim tHeaders = {null}Ý%gÖòÄbbs.vrbrothers.comüôânög
Ý%gÖòÄbbs.vrbrothers.comüôânögÝ%gÖòÄbbs.vrbrothers.comüôânög
Ý%gÖòÄbbs.vrbrothers.comüôânög
复制代码 发送post请求- Import "SHTTP.lua"Ý%gÖòÄbbs.vrbrothers.comüôânög
Ý%gÖòÄbbs.vrbrothers.comüôânögÝ%gÖòÄbbs.vrbrothers.comüôânög
Ý%gÖòÄbbs.vrbrothers.comüôânög
- Dim sUrl= "https://api.toolnb.com/Tools/Qrcode/qrcodeLogo.html"Ý%gÖòÄbbs.vrbrothers.comüôânög
Ý%gÖòÄbbs.vrbrothers.comüôânögÝ%gÖòÄbbs.vrbrothers.comüôânög
Ý%gÖòÄbbs.vrbrothers.comüôânög
复制代码- Import "SHTTP.lua"Ý%gÖòÄbbs.vrbrothers.comüôânög
Ý%gÖòÄbbs.vrbrothers.comüôânögÝ%gÖòÄbbs.vrbrothers.comüôânög
Ý%gÖòÄbbs.vrbrothers.comüôânög
- Ý%gÖòÄbbs.vrbrothers.comüôânög
Ý%gÖòÄbbs.vrbrothers.comüôânögÝ%gÖòÄbbs.vrbrothers.comüôânög
Ý%gÖòÄbbs.vrbrothers.comüôânög
- Dim tHeaders = {null}Ý%gÖòÄbbs.vrbrothers.comüôânög
Ý%gÖòÄbbs.vrbrothers.comüôânögÝ%gÖòÄbbs.vrbrothers.comüôânög
Ý%gÖòÄbbs.vrbrothers.comüôânög
- tHeaders["user-agent"] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36"Ý%gÖòÄbbs.vrbrothers.comüôânög
Ý%gÖòÄbbs.vrbrothers.comüôânögÝ%gÖòÄbbs.vrbrothers.comüôânög
Ý%gÖòÄbbs.vrbrothers.comüôânög
复制代码 通过post来提交文件- Import "SHTTP.lua"Ý%gÖòÄbbs.vrbrothers.comüôânög
Ý%gÖòÄbbs.vrbrothers.comüôânögÝ%gÖòÄbbs.vrbrothers.comüôânög
Ý%gÖòÄbbs.vrbrothers.comüôânög
- Dim sUrl= "https://api.toolnb.com/Tools/Qrcode/qrcodeLogo.html"Ý%gÖòÄbbs.vrbrothers.comüôânög
Ý%gÖòÄbbs.vrbrothers.comüôânögÝ%gÖòÄbbs.vrbrothers.comüôânög
Ý%gÖòÄbbs.vrbrothers.comüôânög
复制代码 Ý%gÖòÄbbs.vrbrothers.comüôânögÝ%gÖòÄbbs.vrbrothers.comüôânögÝ%gÖòÄbbs.vrbrothers.comüôânögÝ%gÖòÄbbs.vrbrothers.comüôânögÝ%gÖòÄbbs.vrbrothers.comüôânögÝ%gÖòÄbbs.vrbrothers.comüôânög对接百度OCR识别API- Dim sUrl = "https://aip.baidubce.com/oauth/2.0/token"Ý%gÖòÄbbs.vrbrothers.comüôânög
Ý%gÖòÄbbs.vrbrothers.comüôânögÝ%gÖòÄbbs.vrbrothers.comüôânög
Ý%gÖòÄbbs.vrbrothers.comüôânög
- Dim tData = {null}Ý%gÖòÄbbs.vrbrothers.comüôânög
Ý%gÖòÄbbs.vrbrothers.comüôânögÝ%gÖòÄbbs.vrbrothers.comüôânög
Ý%gÖòÄbbs.vrbrothers.comüôânög
- tData["grant_type"] = "client_credentials"Ý%gÖòÄbbs.vrbrothers.comüôânög
Ý%gÖòÄbbs.vrbrothers.comüôânögÝ%gÖòÄbbs.vrbrothers.comüôânög
Ý%gÖòÄbbs.vrbrothers.comüôânög
- tData["client_id"] = "" // 填自己的client_idÝ%gÖòÄbbs.vrbrothers.comüôânög
Ý%gÖòÄbbs.vrbrothers.comüôânögÝ%gÖòÄbbs.vrbrothers.comüôânög
Ý%gÖòÄbbs.vrbrothers.comüôânög
- tData["client_secret"] = "" // 填自己的client_secretÝ%gÖòÄbbs.vrbrothers.comüôânög
Ý%gÖòÄbbs.vrbrothers.comüôânögÝ%gÖòÄbbs.vrbrothers.comüôânög
Ý%gÖòÄbbs.vrbrothers.comüôânög
- Dim sJson, tJsonÝ%gÖòÄbbs.vrbrothers.comüôânög
Ý%gÖòÄbbs.vrbrothers.comüôânögÝ%gÖòÄbbs.vrbrothers.comüôânög
Ý%gÖòÄbbs.vrbrothers.comüôânög
- // 获取api的access_token值Ý%gÖòÄbbs.vrbrothers.comüôânög
Ý%gÖòÄbbs.vrbrothers.comüôânögÝ%gÖòÄbbs.vrbrothers.comüôânög
Ý%gÖòÄbbs.vrbrothers.comüôânög
- sJson = SHTTP.Post(sUrl, tData)Ý%gÖòÄbbs.vrbrothers.comüôânög
Ý%gÖòÄbbs.vrbrothers.comüôânögÝ%gÖòÄbbs.vrbrothers.comüôânög
Ý%gÖòÄbbs.vrbrothers.comüôânög
- tJson = Cjson.Decode(sJson)Ý%gÖòÄbbs.vrbrothers.comüôânög
Ý%gÖòÄbbs.vrbrothers.comüôânögÝ%gÖòÄbbs.vrbrothers.comüôânög
Ý%gÖòÄbbs.vrbrothers.comüôânög
- Dim Access_Token = tJson["access_token"]Ý%gÖòÄbbs.vrbrothers.comüôânög
Ý%gÖòÄbbs.vrbrothers.comüôânögÝ%gÖòÄbbs.vrbrothers.comüôânög
Ý%gÖòÄbbs.vrbrothers.comüôânög
- Ý%gÖòÄbbs.vrbrothers.comüôânög
Ý%gÖòÄbbs.vrbrothers.comüôânögÝ%gÖòÄbbs.vrbrothers.comüôânög
Ý%gÖòÄbbs.vrbrothers.comüôânög
- Ý%gÖòÄbbs.vrbrothers.comüôânög
Ý%gÖòÄbbs.vrbrothers.comüôânögÝ%gÖòÄbbs.vrbrothers.comüôânög
Ý%gÖòÄbbs.vrbrothers.comüôânög
- sUrl = "https://aip.baidubce.com/rest/2.0/ocr/v1/general_basic" & "?access_token=" & Access_TokenÝ%gÖòÄbbs.vrbrothers.comüôânög
Ý%gÖòÄbbs.vrbrothers.comüôânögÝ%gÖòÄbbs.vrbrothers.comüôânög
Ý%gÖòÄbbs.vrbrothers.comüôânög
- // 需要先将图片转成base64编码Ý%gÖòÄbbs.vrbrothers.comüôânög
Ý%gÖòÄbbs.vrbrothers.comüôânögÝ%gÖòÄbbs.vrbrothers.comüôânög
Ý%gÖòÄbbs.vrbrothers.comüôânög
- Dim ImgBase64 = ShanHai.ReadFileBase(GetSdcardDir() & "/Pictures/test.png")Ý%gÖòÄbbs.vrbrothers.comüôânög
Ý%gÖòÄbbs.vrbrothers.comüôânögÝ%gÖòÄbbs.vrbrothers.comüôânög
Ý%gÖòÄbbs.vrbrothers.comüôânög
- // 对内容进行url编码Ý%gÖòÄbbs.vrbrothers.comüôânög
Ý%gÖòÄbbs.vrbrothers.comüôânögÝ%gÖòÄbbs.vrbrothers.comüôânög
Ý%gÖòÄbbs.vrbrothers.comüôânög
- ImgBase64 = ShanHai.CharToUrl(ImgBase64)Ý%gÖòÄbbs.vrbrothers.comüôânög
Ý%gÖòÄbbs.vrbrothers.comüôânögÝ%gÖòÄbbs.vrbrothers.comüôânög
Ý%gÖòÄbbs.vrbrothers.comüôânög
- Ý%gÖòÄbbs.vrbrothers.comüôânög
Ý%gÖòÄbbs.vrbrothers.comüôânögÝ%gÖòÄbbs.vrbrothers.comüôânög
Ý%gÖòÄbbs.vrbrothers.comüôânög
- sJson = SHTTP.Post(sUrl, {"image":ImgBase64},{"headers":{"Content-Type":"application/x-www-form-urlencoded"}})Ý%gÖòÄbbs.vrbrothers.comüôânög
Ý%gÖòÄbbs.vrbrothers.comüôânögÝ%gÖòÄbbs.vrbrothers.comüôânög
Ý%gÖòÄbbs.vrbrothers.comüôânög
- tJson = Cjson.Decode(sJson)Ý%gÖòÄbbs.vrbrothers.comüôânög
Ý%gÖòÄbbs.vrbrothers.comüôânögÝ%gÖòÄbbs.vrbrothers.comüôânög
Ý%gÖòÄbbs.vrbrothers.comüôânög
- For i = 1 To Len(tJson["words_result"])Ý%gÖòÄbbs.vrbrothers.comüôânög
Ý%gÖòÄbbs.vrbrothers.comüôânögÝ%gÖòÄbbs.vrbrothers.comüôânög
Ý%gÖòÄbbs.vrbrothers.comüôânög
- TracePrint tJson["words_result"][i]["words"]Ý%gÖòÄbbs.vrbrothers.comüôânög
Ý%gÖòÄbbs.vrbrothers.comüôânögÝ%gÖòÄbbs.vrbrothers.comüôânög
Ý%gÖòÄbbs.vrbrothers.comüôânög
- NextÝ%gÖòÄbbs.vrbrothers.comüôânög
Ý%gÖòÄbbs.vrbrothers.comüôânögÝ%gÖòÄbbs.vrbrothers.comüôânög
Ý%gÖòÄbbs.vrbrothers.comüôânög
复制代码 Ý%gÖòÄbbs.vrbrothers.comüôânög Ý%gÖòÄbbs.vrbrothers.comüôânögÝ%gÖòÄbbs.vrbrothers.comüôânög Ý%gÖòÄbbs.vrbrothers.comüôânög插件开源下载(回复可见):Ý%gÖòÄbbs.vrbrothers.comüôânög [attach]251160[/attach] Ý%gÖòÄbbs.vrbrothers.comüôânögÝ%gÖòÄbbs.vrbrothers.comüôânög Ý%gÖòÄbbs.vrbrothers.comüôânögÝ%gÖòÄbbs.vrbrothers.comüôânög Ý%gÖòÄbbs.vrbrothers.comüôânögÝ%gÖòÄbbs.vrbrothers.comüôânög Ý%gÖòÄbbs.vrbrothers.comüôânögÝ%gÖòÄbbs.vrbrothers.comüôânög Ý%gÖòÄbbs.vrbrothers.comüôânög
|