问题比较小白,各位海涵。
客户端dojo
服务端 node.js+express
需求这样。客户端调用
xhr.put({ url: "workspace/project1/doc/123.html", putData: "ssssssssssssssss", handleAs: "text", contentType: “text/html” });
期望在服务端对应目录生成123.HTML这个文件,数据为putData里面的。
服务端怎么搞?目前服务端代码如下。
app.put('.',function(req, res){ console.log(req.params); console.log(req.putData);
//收到数据调用 fs模块刷磁盘。 不知道怎么写了?
}); 请指教????
截取了下报文,数据有但是不知道拿? PUT http://127.0.0.1:3000/workspace/project1/doc/123.html HTTP/1.1 Host: 127.0.0.1:3000 User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:20.0) Gecko/20100101 Firefox/20.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8 Accept-Language: zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3 Accept-Encoding: gzip, deflate Content-Type: text/html; charset=UTF-8 X-Requested-With: XMLHttpRequest Referer: http://127.0.0.1:3000/ Content-Length: 16 Connection: keep-alive
ssssssssssssssss
最终我有调试了下代码? 发现客户端其实就这样 xhr.open("put","123.html",true); xhr.send(“aaaaaaaaa”);
服务端 怎么获取 xhr.send 参数数据啊?
包里面也有 如下 PUT http://127.0.0.1:3000/workspace/project1/doc/123.html HTTP/1.1 Host: 127.0.0.1:3000 User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:20.0) Gecko/20100101 Firefox/20.0 Accept: textml,application/xhtml+xml,application/xml;q=0.9,/;q=0.8 Accept-Language: zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3 Accept-Encoding: gzip, deflate Content-Type: textml; charset=UTF-8 X-Requested-With: XMLHttpRequest Referer: http://127.0.0.1:3000/ Content-Length: 18 Connection: keep-alive
bbbbbbbbbbbbbbbbbb
摸索出来了。补充一下在。
如果是带参数方式如 123.html?id=aa&name=xxx 这种常规拿即可。如果直接put数据 即
xhr.open("put","123.html",ture);
xhr.send(“aaaaaa”);//
要获取send参数的话。服务端修改如下即可。
app.put('.',function(req, res){ var putData = ""; req.on("data", function(postDataChunk) { putData += postDataChunk; }); req.on("end", function() { console.log(“all data is '” + putData + “’.”); //返回标示 res.end(“ok”); }); });