CNode

大家进来看看帮帮忙~~~~

Bbeiyio发布于14 年前最后回复14 年前6 回复4673 浏览0 收藏
/** 主函数*/
function main(a_route,a_handle) {

	function onRequest(a_req, a_res) {
		
		a_res.writeHead(200, {'Content-Type': 'text/plain'}); 
		
		a_req.setEncoding('utf8'); 
		
		var t_str=urllib.parse(a_req.url,true).query.json;//接收字符串
		
		/********************/
		console.log("1url:\n"+a_req.url);
		
		console.log("data:\n"+t_str);
		
		/********************/
		
		var t_obj=JSON.parse(t_str);//将字符串转换成json
		
		a_route(a_handle,t_obj.interfaceid,t_obj,a_res);
		
		a_res.end();
	
	}
	http.createServer(onRequest).listen(port);

}

写了以上的代码,用浏览器访问http://192.168.0.152:8888/?json={"interfaceid":"0x1001","mac":"cat","gameid":"23"} 是可以正确解析和使用的, 用C++的编写了一个client端进行访问的时候以上代码报错,经过打印发现时URL为空,找了好久找不是哪里写的问题,client可以跟定是发送了东西的。请高手指点下

查看回复

回复 (6)

参与回复
登录后即可参与回复。登录