function MainScene:ctor() local url = "http://localhost/request.php" local request = network.createHTTPRequest(onRequestFinished, url, "POST") request:addPOSTValue("KEY", "VALUE") -- 开始请求。当请求完成时会调用 callback() 函数 request:start() end
---注意onRequestFinished前面,不要加MainScence function onRequestFinished(event) local ok = (event.name == "completed") local request = event.request
if not ok then -- 请求失败,显示错误代码和错误消息 print(request:getErrorCode(), request:getErrorMessage()) return end
local code = request:getResponseStatusCode() if code ~= 200 then -- 请求结束,但没有返回 200 响应代码 print(code) return end
-- 请求成功,显示服务端返回的内容 local response = request:getResponseString() print(response) end
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn