CNode

请问这两个http请求是等效的吗?

问答
Lluoyuxiang61发布于8 年前最后回复8 年前3 回复2813 浏览0 收藏

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

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

查看回复

回复 (3)

I
im-here#1·8 年前

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

A
atian25#2·8 年前

第一个你没调用 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. **

参与回复
登录后即可参与回复。登录