企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
## 这里演示了sockets的使用方法: ~~~lua|woo print('sockets模拟http请求测试(正常情况下,请勿这样使用,请使用正规的http模块,这里仅仅探索sockets使用方法):') local sock = woo.sockets:new() local isok = sock:dial('tcp', 'www.baidu.com:80', function() print('在这个函数内,sockets有效,函数结束后,sockets自动关闭') _out('拨通远程ip ok', '\n') r = sock:write(_bytes("GET / HTTP/1.1\r\n" .. "Host: www.baidu.com\r\n" .. "User-Agent: curl/7.10\r\n" .. "Connection: Close\r\n\r\n")) _out('发送http头部信息字节长度:', r, '\n') --r = sock:write(0x05, 0x05) print('===字节集在转换为字符串时需要注意,单字节大小不能超过255,应当在0-255范围内,请勿修改字节集中的数据===') local b, e = sock:readAll(false) --local b, e = sock:readAll(true) rule_re = '<title>(.*?)</title>' _out('sockets模拟http请求 访问百度首页并使用正则[' .. rule_re .. ']匹配标题:', _re_match(_str(b), rule_re)[1][2], '\n') --print("sockets模拟http请求最终结果:", b, e) end) print('sockets 是否成功:',isok) ~~~