脚本宝典收集整理的这篇文章主要介绍了javascript代码实例教程-node-request(),脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。小宝典致力于为广大程序猿(媛)提供高品质的代码服务,请大家多多光顾小站,小宝典在此谢过。
1、上篇文章get 就是在request这个方法上面封装的;
2、下面就不写了,直接上图和代码
从图片上面看红色的“正常评论”,是我通过评论区正常评论的;记得打开调试窗口,看Network 图片上面的2楼,与3楼比较,之所以字没有打完,是Cookies里面的Content-Length设定的值小了;后台会把上送的值与Cookies设定的参数作比较; 3、4楼就正常了,我把上宋的值与Content-Length的值相对应了;
所有的参数都从Network中获取; 图片中Request Headers中的参数写到下面代码options中的headers中去,记住要做成json格式;
const http = require("http"); const querystring = require("querystring"); const postData = querystring.stringify({ content:"测试3:node写入,管理员不要封我的号哦!", id:"53002747" }); const options = { hostname:"blog.csdn.net", port:"80", path:"/u014150409/comment/submIT", method:"POST", headers:{ "Accept":"*/*", "Accept-Encoding":"gzip, deflate", "Accept-Language":"zh-CN,zh;q=0.8", "Connection":"keep-alive", "Content-Length":postData.length, "Content-tyPE":"application/x-www-form-urlencoded; charset=UTF-8", "Cookie":"bdshare_Firstime=1476801810724; dc_session_id=1483968478194", "Host":"bLOG.csdn.net", "Origin":"https://blog.csdn.net", "Referer":"https://blog.csdn.net/u014150409/article/details/53002747", "User-Agent":"mozilla/5.0 (Windows NT 6.1; WOW64) Applewebkit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36", "X-Requested-With":"XMLHttPRequest" } } const req = http.request(options,function(res){ console.log("status:"+res.statusCode); console.log("headers:"+JSON.stringify(res.headers)); res.on("data",function(chunk){ console.log(Buffer.isBuffer(chunk)); console.log(typeof chunk); }) res.on("end",function(){ console.log("评论完毕"); }) }); req.on("error",function(e){ console.log("Error:"+ e.message); }) req.write(postData); req.end();
觉得可用,就经常来吧! 脚本宝典 欢迎评论哦! js脚本,巧夺天工,精雕玉琢。小宝典献丑了!
以上是脚本宝典为你收集整理的javascript代码实例教程-node-request()全部内容,希望文章能够帮你解决javascript代码实例教程-node-request()所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。