fightingly369 2017-05-18 14:22 采纳率: 0%
浏览 1148

在本地的http.request规定了post方法,但在chrome控制台显示的是get方法

//server端
var http = require("http");
http.createServer(function(request, response) {

if(request.method == 'POST'){
console.log('really');
var postdata='';
request.on('data',function(postchunk){
postdata+=postchunk;

        console.log('datais ==',postdata);
    });
}
response.writeHead(200, {"Content-Type": "text/plain"});  
response.write("welcome to the nodejs  world ");  
response.end();

}).listen(8888);
console.log("nodejs start listen 8888 port!");

//client端
var http = require("http");
var querystring =require('querystring');
var postData = querystring.stringify({
content:'加油加油加油',
belongId:2862414
});
var options = {
hostname: 'localhost',
port: 8888,
//path: '/test?params1="123"&params2=456',
method: 'POST'
};

var req = http.request(options, function(res) {
console.log('STATUS: ' + res.statusCode);
console.log('HEADERS: ' + JSON.stringify(res.headers));
res.setEncoding('utf8');

res.on('data', function (chunk) {
console.log('BODY: ' + chunk);
});
});

req.on('error', function(e) {
console.log('problem with request: ' + e.message);
});

// write data to request body
req.write(postData);
req.end();
图片说明

  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥15 vc6.0中想运行代码的时候总是提示无法打开文件是怎么回事
    • ¥25 关于##爬虫##的问题,如何解决?:
    • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
    • ¥15 找一位技术过硬的游戏pj程序员
    • ¥15 matlab生成电测深三层曲线模型代码
    • ¥50 随机森林与房贷信用风险模型
    • ¥50 buildozer打包kivy app失败
    • ¥30 在vs2022里运行python代码
    • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
    • ¥15 求解 yolo算法问题