亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

您的位置:首頁技術文章
文章詳情頁

html - node.js為啥抓取不了前端傳過來的數據?

瀏覽:145日期:2023-10-09 18:55:25

問題描述

用node.js抓取不了前端表單的數據,哭哭哭這是node.js代碼

var http=require('http');var url=require('url');var dns=require('dns');var fs=require('fs');var querystring=require('querystring');var postdata='';http.createServer(function(req,res){ req.setEncoding('utf8'); //var readPath=dirname+'/'+url.parse(’a.html’).pathname; var pathname=url.parse(req.url).pathname; if(pathname==='/'){res.writeHead(200,{’Content-Type’:’text/html’});var indexpage=fs.readFileSync('a.html'); //console.log(indexpage); res.end(indexpage); } if(pathname==='/about'){res.writeHead(200,{’Content-Type’:’text/plain’});req.addListener('data',function(chunk){ if(chunk){postdata+=chunk; console.log(chunk); }elseconsole.log('no data emit')}); req.addListener('end',function(postdata){var a=querystring.parse(postdata);console.log(postdata)console.log(a);res.end(a.text); });}console.log('Server has been running on port 3000'); }).listen('3000','127.0.0.1');這是HTML代碼<!DOCTYPE html><html><head><meta charset='utf-8'><meta name='author' content='sinson'></head><body><form action='/about' method='get'><input type='text' name='text'><input type='submit' value='提交'></form></body></html>

求大神指教

問題解答

回答1:

你只處理了body部分的數據,然而前端的提交方法是get...建議去了解一下get和post的基本區別...

修改之后的app.js

var http = require('http');var url = require('url');var dns = require('dns');var fs = require('fs');var querystring = require('querystring');var postdata = '';http.createServer(function (req, res) { req.setEncoding('utf8'); // var readPath=dirname+'/'+url.parse(’a.html’).pathname; var pathname = url.parse(req.url).pathname; if (pathname === '/') { res.writeHead(200, { ’Content-Type’: ’text/html’ }); var indexpage = fs.readFileSync('a.html'); // console.log(indexpage); res.end(indexpage); } if (pathname === '/about') { res.writeHead(200, { ’Content-Type’: ’text/plain’ }); req.addListener('data', function (chunk) { if (chunk) {postdata += chunk;console.log(chunk); } elseconsole.log('no data emit'); }); req.addListener('end', function () { //去掉參數 var a = querystring.parse(postdata); console.log(postdata); console.log(a); res.end(a.text); }); }}).listen('3000', '127.0.0.1');console.log('Server has been running on port 3000');//提到外面比較好

a.html

<!DOCTYPE html><html><head><meta charset='utf-8'><meta name='author' content='sinson'></head><body><form action='/about' method='POST'> <!--改為POST--><input type='text' name='text'><input type='submit' value='提交'></form></body></html>

標簽: HTML
相關文章:
主站蜘蛛池模板: 国产色司机在线视频免费观看 | 精品小视频在线观看 | 国产乱理论片在线观看理论 | 国产成人精品亚洲午夜麻豆 | 久久久久亚洲香蕉网 | 青草视频入口 在线观看 | 高潮岳喷我一脸 | 成人免费福利网站在线看 | 日本一级毛片在线播放 | 国产一区免费视频 | 国产伦一区二区三区免费 | 2022在线精品视频网站 | 高清一级做a爱免费视 | 亚洲精品www | 欧美高清在线视频一区二区 | 片成年免费观看网站黄 | 成年女人视频播放免费观看 | 成人做爰网站 | 成人黄18免费视频 | 极品美女一级毛片免费 | 站长推荐精品午夜免费影院 | 极品毛片| 黄色仓库在线观看 | 最近中文字幕免费完整 | 激情影院成人区免费观看视频 | 国产主播第一页 | 欧美日韩一区二区不卡三区 | 色亚洲影院 | 亚洲欧美日本国产综合在线 | 欧美三级毛片 | 九九亚洲精品 | 深夜成人性视频免费看 | 国产在线成人精品 | 丁香午夜婷婷 | 国产成人精品高清免费 | 久久不卡视频 | 国产高清视频在线观看不卡v | 尤物视频网站在线观看 | 91免费国产在线观看 | 久久九九国产精品怡红院 | 欧美三级免费 |