带节点的Http请求? [英] Http request with node?

查看:136
本文介绍了带节点的Http请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用与此代码等效的node.js发出Http请求:

How do I make a Http request with node.js that is equivalent to this code:

curl -X PUT http://localhost:3000/users/1


推荐答案

使用 http客户端

这些行:

var http = require('http');
var client = http.createClient(3000, 'localhost');
var request = client.request('PUT', '/users/1');
request.write("stuff");
request.end();
request.on("response", function (response) {
    // handle the response
});

这篇关于带节点的Http请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆