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 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
    • ¥30 截图中的mathematics程序转换成matlab
    • ¥15 动力学代码报错,维度不匹配
    • ¥15 Power query添加列问题
    • ¥50 Kubernetes&Fission&Eleasticsearch
    • ¥15 報錯:Person is not mapped,如何解決?
    • ¥15 c++头文件不能识别CDialog
    • ¥15 Excel发现不可读取的内容
    • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
    • ¥20 yolov5自定义Prune报错,如何解决?