访问远程数据相关函数 本文简述访问远程数据相关函数的语法、作用、入参、返回值、示例。 ctyun.queryremote 函数信息详见下表: 项目 描述 语法 res, err ctyun.queryremote(url, reqinfo, timeout?, direct2client?) 作用 利用cosocket访问第三方网站,得到响应内容。支持简单的单次请求得到响应并处理、响应内容直接发送至客户端两种模式。 入参 url:访问第三方服务的url。示例:" reqinfo:请求信息,包括requestmethod,request body(POST时候需要),request headers,是否打开ssl认证。示例: { method "POST", body "hello world", headers {}, sslverify true } timeout: 超时时间,单位为毫秒。示例:30000,表示超时时间为30s。 direct2client: 是否直接发送至客户端,布尔型。示例:true,标识直接发送至客户端。注:开启时请求第三方的requestmethod需要跟客户端请求一致。 返回值 res:响应结果,luatable类型,{ status, headers, body }。当开启direct2client时此项为字符串done。 err:错误信息。 示例: 简单的单次请求 lua local res, err ctyun.queryremote(" { method "POST", body "a1&b2", headers { ["ContentType"] "application/xwwwformurlencoded", }, }, 30000) if err then return end At this point, the entire request / response is complete and the connection will be closed or back on the connection pool. local status res.status local length res.headers["ContentLength"] local body res.body 响应直接发送客户端 pgsql local res, err ctyun.queryremote(" { method "GET", headers { ["ContentType"] "application/xwwwformurlencoded", }, }, 30000, true) if err then return end