跳到主要内容
CNode

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

问答
Lluoyuxiang61发布于 9 年前最后回复 9 年前
328380

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

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

查看回复

回复 (3)

A
atian25#29 年前

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

I
im-here#19 年前

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

参与回复

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