请问这两个http请求是等效的吗?
发布于 6 年前 作者 luoyuxiang61 2299 次浏览 来自 问答

http.request req.PNG http.get get.PNG

我用第一种方法(http.request)没有任何响应,用第二种(http.get)就可以拿到数据。

3 回复

监听一下 error ,看看第一种情况是不是error 不过我一般都用request模块

第一个你没调用 req.end(); 文档里面写的清清楚楚的:

Since most requests are GET requests without bodies, Node.js provides this convenience method. The only difference between this method and http.request() is that it sets the method to GET and **calls req.end() automatically. **

@atian25 解决了,感谢!

回到顶部