关于request.write(postData) ,服务器请求的参数值为空,已解决
var http = require("http"); var querystring = require("querystring"); var eventer = require("events").EventEmitter; var closedEventer = new eventer(); var postData = querystring.stringify({ "type":"1", "mobile":"152****7990", "category":"r" }); var options = { hostname:"www.szzy888.com", port:8080, path:"/studio/app/sendcode.do", method:"post", headers:{ "Host":"www.szzy888.com", "Referer":"http://www.szzy888.com", "User-Agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:49.0) Gecko/20100101 Firefox/49.0" } }; var response = ""; var req = http.request(options,function(res){ console.log("state:"+res.statusCode + "\n"); console.log("header:"+JSON.stringify(res.headers) + "\n"); res.on("data",function(data){ console.log(typeof data); response += data; }); res.on("end",function(){ console.log("response :"+response + "\n"); //var result = JSON.parse(response); }); }) req.on("error",function(e){ console.log("error:"+e.message + "\n"); }); req.write(postData); req.end();
//以上代码
但是我在服务器接收参数的时候无法获取到参数value,后来经我调整成
var options = { hostname:"www.szzy888.com", port:8080, path:"/studio/app/sendcode.do?"+postData, method:"post", headers:{ "Host":"www.szzy888.com", "Referer":"http://www.szzy888.com", "User-Agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:49.0) Gecko/20100101 Firefox/49.0" } };
反而成功了~ 请帮忙解答下修改前出现问题原因???
还有服务器使用的是JAVA语言开发,并且服务器获取的时候使用
String type = request.getParameter("type"); String mobile = request.getParameter("mobile"); String category = request.getParameter("category");