请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

问一下express中的post方法问题

我做了一个简单的post方法,想直接console.log "hello"在cmd中。但是我在网页中打开http://localhost:5000/p 却无法显示“hello”在cmd中。而如果我在网页中打开http://localhost:5000/c (即下面的get方法)却可以显示“hi”在cmd中。求解决办法。

var express = require('express');
var app = express();

app.post('/p', function(request,response){    
 //const comment=request.body.body;    
 console.log("hello");  
  // response.send('hello')
  });
  
  app.get('/c', function(request,response){   
    console.log("hi");  
    response.send("hello");  
    });
var port =process.env.PORT || 5000;
app.listen(port,function(){    console.log("listen on" + port);});

正在回答 回答被采纳积分+3

1回答

双越 2019-10-26 13:48:32

网页直接访问,只会发 get 请求。想要模拟一个 post 请求,必须用 postman 来做。

课程中有讲 postman 的使用。

0 回复 有任何疑惑可以回复我~
问题已解决,确定采纳
还有疑问,暂不采纳
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号