Node.js 调用 restful webservice
如何构建一个restful web service参考原来的文章
http://www.cnblogs.com/ericnie/p/5212748.html
直接用原来的项目编译好像有问题,此处耗费1个半钟头,新建立一个项目就完全OK了 :-(
写一个callrest.js,代码如下:
|
var http = require('http'); var username = 'falcon'; var options = { var req = http.request(options, function (res) { res.on('data',function (chunk) { req.on('error', function(e) { req.end(); |
之前在设置'content-type': "application/atom+xml",结果得到错误
STATUS: 415,查了后是返回的格式不支持,然后修改为application/json或者application/xml就通过了,因为后端restful代码写的是
application/json和application/xml
执行node callrest.js输出如下:
[weblogic@ericnie nodejs-cluster]$ node callrest.js
STATUS: 200
HEADERS: {"connection":"close","date":"Fri, 14 Oct 2016 03:30:31 GMT","content-length":"981","content-type":"application/json"}
BODY: [{"firstname":"Firstname 0","hiredate":"2016-10-14T11:30:31.124+08:00","id":0,"lastname":"Last 0"},{"firstname":"Firstname 1","hiredate":"2016-10-14T11:30:31.124+08:00","id":1,"lastname":"Last 1"},{"firstname":"Firstname 2","hiredate":"2016-10-14T11:30:31.124+08:00","id":2,"lastname":"Last 2"},{"firstname":"Firstname 3","hiredate":"2016-10-14T11:30:31.124+08:00","id":3,"lastname":"Last 3"},{"firstname":"Firstname 4","hiredate":"2016-10-14T11:30:31.124+08:00","id":4,"lastname":"Last 4"},{"firstname":"Firstname 5","hiredate":"2016-10-14T11:30:31.124+08:00","id":5,"lastname":"Last 5"},{"firstname":"Firstname 6","hiredate":"2016-10-14T11:30:31.124+08:00","id":6,"lastname":"Last 6"},{"firstname":"Firstname 7","hiredate":"2016-10-14T11:30:31.124+08:00","id":7,"lastname":"Last 7"},{"firstname":"Firstname 8","hiredate":"2016-10-14T11:30:31.124+08:00","id":8,"lastname":"Last 8"},{"firstname":"Firstname 9","hiredate":"2016-10-14T11:30:31.124+08:00","id":9,"lastname":"Last 9"}]
Node.js 调用 restful webservice的更多相关文章
- node.js 调用天气webservice接口
首先安装soap模块 npm install soap 1 2 3 4 5 6 7 8 9 10 var soap = require('soap'); var url = 'http://w ...
- Node.js调用百度地图Web服务API的Geocoding接口进行点位反地理信息编码
(从我的新浪博客上搬来的,做了一些修改.) 最近迷上了node.js以及JavaScript.现在接到一个活,要解析一个出租车点位数据的地理信息.于是就想到使用Node.js调用百度地图API进行解析 ...
- 使用Node.js调用阿里云短信的发送以及接收
为了使用Node.js调用阿里云短信服务,我自己写了个npm包, 目前实现了: 使用Node.js调用阿里云短信服务,发送短信: 使用Node.js调用阿里云短信服务以及MNS服务,接收用户上行短信 ...
- Node.js调用C#代码
在Node.js的项目中假如我们想去调用已经用C#写的dll库该怎么办呢?在这种情况下Edge.js是一个不错的选择,Edge.js是一款在GitHub上开源的技术,它允许Node.js和.NET c ...
- windows下node.js调用bat
node.js调用bat需要用到Child Processes模块 因为bat是文件,所以需要使用execFile方法 如果指定了cwd,它会切换bat执行的目录,类似cd的功能,如果未指定默认为 ...
- Node.js实现RESTful api,express or koa?
文章导读: 一.what's RESTful API 二.Express RESTful API 三.KOA RESTful API 四.express还是koa? 五.参考资料 一.what's R ...
- $ npm install opencv ? 你试试?! 在windows环境下,使用node.js调用opencv攻略
博主之前写过一篇文章<html5与EmguCV前后端实现——人脸识别篇>,叙述的是opencv和C#的故事.最近在公司服务器上更新了一套nodejs环境,早就听闻npm上有opencv模块 ...
- 解决Node.js调用fs.renameSync报错的问题(Error: EXDEV, cross-device link not permitted)
2014-08-23 今天开始学习Node.js,在写一个文件上传的功能时候,调用fs.renameSync方法错误 出错代码所在如下: function upload(response,reques ...
- Node.js:RESTful API
ylbtech-Node.js:RESTful API 1.返回顶部 1. Node.js RESTful API 什么是 REST? REST即表述性状态传递(英文:Representational ...
随机推荐
- noip2016 提高组
T1 玩具谜题 题目传送门 这道题直接模拟就好了哇 233 #include<cstdio> #include<cstring> #include<algorithm&g ...
- arm SecurCore 处理器【转】
转自:http://www.arm.com/zh/products/processors/securcore/index.php SecurCore 处理器 (View Larger SecurCor ...
- css3 不常用但重要的属性
IOS 2.-webkit-touch-callout (ios 2.0+) none:禁止弹出系统弹窗 default:默认 Android Common 1.-webkit-user-select ...
- SQLAlchemy中filter()和filter_by()有什么区别
from:https://segmentfault.com/q/1010000000140472 filter: apply the given filtering criterion to a co ...
- elasticSearch script api
Package org.elasticsearch.script Support for running user provided scripts (in the request, in clust ...
- [BZOJ1494][NOI2007]生成树计数 状压dp 并查集
1494: [NOI2007]生成树计数 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 793 Solved: 451[Submit][Status][ ...
- AC日记——中山市选[2009]小明的游戏 bzoj 2464
2464 思路: 最短路: 代码: #include <cstdio> #include <cstring> #include <iostream> #includ ...
- HDU 6351.Beautiful Now-暴力、全排列、思维 (2018 Multi-University Training Contest 5 1002)
2018 Multi-University Training Contest 5 6351.Beautiful Now 题意就是交换任意两个数字,问你交换k次之后的最小值和最大值. 官方题解: 哇塞, ...
- Jekins持续集成,gitlab代码仓库
http://blog.csdn.net/john_cdy/article/details/7738393
- 【pb_ds】【平衡树启发式合并】【并查集】bzoj2733 [HNOI2012]永无乡
用并查集维护联通性.对每个联通块维护一个平衡树.合并时启发式合并.比较懒,用了pb_ds. #include<cstdio> #include<ext/pb_ds/assoc_con ...