在手机上用Lua做项目需要调用到百度AI的文字识别功能,总时提示:{"error_code":100,"error_msg":"Invalid parameter"},同样的参数与TOKEN在pythone、PHP和postman中测试返回正常
require("TSLib")
sz = require("sz")
http = require("szocket.http")
图片路径=userPath().."/res/tt.png"
图片数据=imageBase64(图片路径)
a=[[{"image":"string"}]]
b=string.gsub(a,"string",图片数据)
json = sz.json
ltn12 = require"ltn12"
response_body = {}
post_data = b
staus,code,header = http.request{
url = "https://aip.baidubce.com/rest/2.0/ocr/v1/general_basic?access_token=24.cff58a10b896dbc1224efc7ff6974702.2592000.1661401756.282335-*%22,
method = "POST",
headers =
{
["Content-Type"] = "application/x-www-form-urlencoded",
},
source = ltn12.source.string(post_data),
sink = ltn12.sink.table(response_body),
}
ret =table.concat(response_body)
nLog(ret)