NodeJS POST Request Over JSON-RPC
1.npm install art-template
2.npm install request
3.在app.js中加入以下代码转html:
var template = require('art-template');
template.config('base', '');
template.config('extname', '.html');
app.engine('.html', template.__express);
app.set('view engine', 'html');
4.在routes/index.js中
var express = require('express');
var router = express.Router();
//var request=require('request');
var request = require("request");
/* GET home page. */
router.get('/', function(req, res, next) {
var headers = {
'Content-Type': 'application/x-www-form-urlencoded',
'Accept': 'application/json-rpc',
'keyname':'XXX'
};
var options = {
url: "XXX",
method: 'POST',
headers: headers,
form: {jsonrpc:'{"method": "XXX", "params": ["XXXXX"], "id": X}'}
};
request(options, function (error, response, body) {
res.render("index", {title:res.statusCode.toString() + " " + body});
});
}); module.exports = router; 将对应的keyname、url、method、params、id改为自己的值
运行结果: 200 {"jsonrpc":"2.0","result":"XXXXX测试数据","id":X}
NodeJS POST Request Over JSON-RPC的更多相关文章
- [转]nodejs使用request发送http请求
本文转自:https://blog.csdn.net/dreamer2020/article/details/52074516/ 在nodejs的开发中,有时需要后台去调用其他服务器的接口,这个时候, ...
- 測试JSON RPC远程调用(JSONclient)
#include <string> #include <iostream> #include <curl/curl.h> /* 标题:JSonclient Auth ...
- 客户端通过Feign发起请求 服务端通过request取 json对象
@RestController @RequestMapping(value = "test") public class TestServer { @RequestMapping( ...
- 获取 request 中 json 数据
import java.io.IOException; import javax.servlet.http.HttpServletRequest; /** * request 对象的相关操作 * @a ...
- flask request 获取json内容2种方式
# -*- coding: utf-8 -*-from flask import request, jsonify, json, Moduleimport loggingfrom web.utils. ...
- 如何使用python内置的request发送JSON格式的数据
使用步骤如下: 一.如果想发送json格式的数据,需要使用request模块中的Request类来创建对象,作为urlopen函数的参数 二.header中添加content-type为applica ...
- Nodejs中request出现ESOCKETTIMEDOUT解决方案
做需求的时候,使用Nodejs的request批量请求某一个接口,由于接口超时,出现 ESOCKETTIMEDOUT,程序中断 为了让程序遇到 ESOCKETTIMEDOUT 之后能够继续执行下去,需 ...
- nodejs get/request
灌水评论示例: var http = require('http'); var querystring = require('querystring'); var postData = queryst ...
- request获取json
$.ajax({ type:'post', url:'${ctx}/recordServiceController/queryDetail.do', //contentType:'applicatio ...
- Google Volley: How to send a POST request with Json data?
sonObjectRequest actuallyaccepts JSONObject as body. From http://arnab.ch/blog/2013/08/asynchronous- ...
随机推荐
- Leetcode Maximum Product Subarray
Find the contiguous subarray within an array (containing at least one number) which has the largest ...
- JNI使用问题记录
此文章包含Android JNI学习过程中的遇到的各种错误记录和学习总结. 1.错误:java.lang.UnsatisfiedLinkError: Native method not found: ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- 【JBOSS】控制台数据库连接信息
数据库连接 信息 进入 在这个页面中(IP和端口已自己的为主):ConnectionCount 这个项目代表在服务开启后,总共使用的连接数!ConnectionCreatedCount ...
- 误删/usr文件夹解决办法
http://blog.chinaunix.net/uid-2623904-id-3044156.html http://www.centoscn.com/CentOS/Intermediate/20 ...
- GIT本地免密配置
在C:\Users\计算机名 下面找到.gitconfig文件(如果没有请新建) 内容为: [user] name = git用户名[user] email = 邮箱 [cred ...
- What's the difference between a stub and mock?
I believe the biggest distinction is that a stub you have already written with predetermined behavio ...
- 如何解决Maple的应用在数学中
对任意数学和技术学科的研究员.教师和学生而言,Maple是一个必备的工具.通过Maple,教师将复杂数学问题注入生命,学生的精力集中在概念理解上而不是如何使用工具上,研究员可以开发更复杂的算法或模型. ...
- linux下git以及github的连接与使用
简单理解 Git 的思想和基本的工作原理,能够更好的进一步和使用Git.在开始学习Git 的时候,最好不要把Git的各种概念和其他的版本控制系统诸如 Subversion 等相比,否则容易混淆每个操作 ...
- 剑指Offer面试题:16.合并两个排序的链表
PS:这也是一道出镜率极高的面试题,我相信很多童鞋都会很眼熟,就像于千万人之中遇见不期而遇的人,没有别的话可说,唯有轻轻地问一声:“哦,原来你也在这里? ” 一.题目:合并两个排序的链表 题目:输入两 ...