比如一个http协议,需要post一个uid给服务端来请求数据,该怎么实现?协议返回时json;
Test-lua里面的例子是没有post内容的:
local xhr = cc.XMLHttpRequest:new()
xhr.responseType = cc.XMLHTTPREQUEST_RESPONSE_JSON
xhr:open(“POST”, “http://httpbin.org/post”)
local function onReadyStateChange()
labelStatusCode:setString(“Http Status Code:”…xhr.statusText)
local response = xhr.response
local output = json.decode(response,1)
table.foreach(output,function(i, v) print (i, v) end)
print(“headers are”)
table.foreach(output.headers,print)
end
xhr:registerScriptHandler(onReadyStateChange)
xhr:send()