Node.js 通过http调用外部接口
2017-01-18 12:14
495 查看
通过http.request发送带参数的post请求
data:发送的内容opt:描述将要发出的请求
data:事件在数据到达时被触发
end:请求结束时触发
error:发生错误时被触发
var http = require("http"); var data = {username:"hello",password:"123456"}; data = JSON.stringify(data); //data = require('querystring').stringify(data); var opt = { host:'localhost', port:'8080', method:'POST', path:'/loginForeign.jspx', headers:{ "Content-Type": 'application/json', "Content-Length": data.length } } var body = ''; var req = http.request(opt, function(res) { console.log("response: " + res.statusCode); res.on('data',function(data){ body += data; }).on('end', function(){ console.log(body) }); }).on('error', function(e) { console.log("error: " + e.message); }) req.write(data); req.end();
相关文章推荐
- C#通过发送 http 请求调用接口之Get
- VB通过http调用验证码短信接口源码
- angularjs $http调用接口的方式
- 如何调用http接口通过get()/post()方法传参
- Node.js 通过https服务器利用js调用网络摄像头
- C#通过发送 http 请求调用接口之Post
- Http下的各种操作类.WebApi系列~通过HttpClient来调用Web Api接口
- python(通过flask实现一个http接口)调用这个接口实现第三方smtp发送邮件
- 通过ffi在node.js中调用动态链接库
- js-template-art【四】通过helper方法注册,调用外部方法
- JS通过Get方式调用接口编码问题
- php通过http调用验证码短信接口源码
- node.js 调用天气webservice接口
- Delphi通过调用Http接口实现短信发送的功能
- http通过get方法调用接口代码部分
- ASP通过http调用验证码短信接口源码
- python通过http请求发送soap报文进行webservice接口调用
- Node.js开发入门—使用http访问外部世界
- [译] 通过 Node.js, Express.js 实现 HTTP/2 Server Push
- 通过flask框架写成http接口调用Ansible