使用HttpClient发送Http请求
local xhr = cc.XMLHttpRequest:new()
xhr.responseType = cc.XMLHTTPREQUEST_RESPONSE_STRING  --返回的数据类型,可以是json等
xhr:open("GET","http://www.baidu.com")
local function onReadyStateChange()
    if xhr.readyState == 4 and xhr.status == 200 then
        print( xhr.response )
    end
    xhr:unregisterScriptHandler()
end
xhr:registerScriptHandler(onReadyStateChange)
xhr:send()  --POST时,可以通过这个发送参数 GET使用链接附带参数

首页 我的博客
粤ICP备17103704号