1、http协议简单使用
1、http协议的简单使用
var express=require('express');
var app=express();
app.get('/index',function(req,res){
var arg=req.query;
console.log(arg);
});
客户端
var
xhr
= cc.loader.getXMLHttpRequest();
xhr.open("GET","http://114.144.246.14:8080/index?account="123",
true);
xhr.onreadystatechange
= function() {
if(xhr.readyState
===
4 && (xhr.status
>= 200
&& xhr.status
< 300)){
console.log("http res("+
xhr.responseText.length
+ "):"
+ xhr.responseText);
try {
var
ret
= JSON.parse(xhr.responseText);
if(handler
!==
null){
handler(ret);
} /* code */
} catch (e) {
console.log("err:"
+ e);
//handler(null);
}
}
};
xhr.send();
会输出{account:'123'}
本文介绍了在 Cocos Creator 中如何简单使用 HTTP 协议,通过示例展示了利用 Express 框架设置服务器接收客户端发送的 account 数据,并进行打印。
http协议&spm=1001.2101.3001.5002&articleId=78145130&d=1&t=3&u=a9e189b78009416ebfd00dad4115a236)
5672

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



