直接贴代码
local xhr = cc.XMLHttpRequest:new()
xhr.responseType = cc.XMLHTTPREQUEST_RESPONSE_JSON --返回数据类型
xhr:open("POST", "http://xxx.xxx.xxx") -- 地址
xhr:setRequestHeader("username", "xxxx") -- 提交的参数
xhr:setRequestHeader("password", "xxxx") -- 提交的参数
local function onReadyStateChange()
print(xhr.response)
end
xhr:registerScriptHandler(onReadyStateChange)
xhr:send()
本文介绍如何使用cc.XMLHttpRequest类在Cocos2d-x中发送POST请求并接收JSON格式的数据。通过设置请求头和响应类型,实现与服务器的交互。
5530

被折叠的 条评论
为什么被折叠?



