var request = require('request');
var options = {
       method: 'post',
url: u,
form: content,
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
}; request(options, function (err, res, body) {
if (err) {
console.log(err)
}else {
console.log(body);
}
})

get

var http = require('http');  

var qs = require('querystring');  

var data = {
a: ,
time: new Date().getTime()};//这是需要提交的数据 var content = qs.stringify(data); var options = {
hostname: '127.0.0.1',
port: ,
path: '/pay/pay_callback?' + content,
method: 'GET'
}; var req = http.request(options, function (res) {
console.log('STATUS: ' + res.statusCode);
console.log('HEADERS: ' + JSON.stringify(res.headers));
res.setEncoding('utf8');
res.on('data', function (chunk) {
console.log('BODY: ' + chunk);
});
}); req.on('error', function (e) {
console.log('problem with request: ' + e.message);
}); req.end();

post:

var http = require('http');  

var qs = require('querystring');  

var post_data = {
a: ,
time: new Date().getTime()};//这是需要提交的数据 var content = qs.stringify(post_data); var options = {
hostname: '127.0.0.1',
port: ,
path: '/pay/pay_callback',
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
}
}; var req = http.request(options, function (res) {
console.log('STATUS: ' + res.statusCode);
console.log('HEADERS: ' + JSON.stringify(res.headers));
res.setEncoding('utf8');
res.on('data', function (chunk) {
console.log('BODY: ' + chunk);
});
}); req.on('error', function (e) {
console.log('problem with request: ' + e.message);
}); // write data to request body
req.write(content); req.end();

nodejs发送http请求的更多相关文章

  1. Nodejs发送Post请求时出现socket hang up错误的解决办法

    参考nodejs官网发送http post请求的方法,实现了一个模拟post提交的功能.实际使用时报socket hang up错误. 后来发现是请求头设置的问题,发送选项中需要加上headers字段 ...

  2. nodejs向远程服务器发送post请求----融云Web SDK/客户端获取token

    最近要用到一个叫融云的及时通讯的SDK,在获取token这个步骤的时候有点卡顿,以防以后碰到类似的问题,再此记录一下. 客户端通过融云 SDK 每次连接服务器时,都需要向服务器提供 Token,以便验 ...

  3. Nodejs Http发送post请求

    Nodejs  Http发送post请求 var http = require('http'); function epay(params) { console.log(" COME IN& ...

  4. [转]nodejs使用request发送http请求

    本文转自:https://blog.csdn.net/dreamer2020/article/details/52074516/ 在nodejs的开发中,有时需要后台去调用其他服务器的接口,这个时候, ...

  5. nodejs获取post请求发送的formData数据

    前端post请求发送formData的类型数据时,需要服务端引入中间件body-parser,主要原因是post请求发送的数据,是在http的body里面,所以需要进行解析,否则获取不到数据(数据为空 ...

  6. 【转】nodejs获取post请求发送的formData数据

    前端post请求发送formData的类型数据时,需要服务端引入中间件body-parser,主要原因是post请求发送的数据,是在http的body里面,所以需要进行解析,否则获取不到数据(数据为空 ...

  7. node - 使用request发送http请求

    在nodejs的开发中,有时需要后台去调用其他服务器的接口,这个时候,就需要发送HTTP请求了.有一个简单的工具可以用,Simplified HTTP request client,可以比较方便的模拟 ...

  8. nodejs的POST请求

    http://blog.csdn.net/puncha/article/details/9015317 Nodejs 发送HTTP POST请求实例 2013-06-03 17:55 71745人阅读 ...

  9. nodejs接收post请求参数

    原文 https://blog.csdn.net/u013263917/article/details/78682270#1.2 nodejs接收post请求参数1.1-浏览器发送post请求参数的方 ...

随机推荐

  1. 干了2个月java开发最深的体会

    综上为JQuery中ajax的操作,感觉使用多了,和form表单的处理还是非常相似的,只不过实现的功能不一样罢了.学习编程,其实就是学习对数据的流转处理,也即是程序的运行流程,如何从前台获取,传输到服 ...

  2. vulcanjs 包类型

    npm 添加在pacakge.json 文件中的 meteor core 包 由meteor 框架提供的 meteor remote 包 从包服务器加载的,使用username:package 格式组 ...

  3. All the Apache Streaming Projects: An Exploratory Guide

    The speed at which data is generated, consumed, processed, and analyzed is increasing at an unbeliev ...

  4. 后台调用前台JS(查看客户端IE版本)

    1.前端代码    </form>    //注意放在form下面<script>    function readRegedit() {        var obj = n ...

  5. led的驱动及测试程序

    一.驱动源码 #include <linux/module.h> #include <linux/kernel.h> #include <linux/fs.h> # ...

  6. jquery tmpl学习资料 --{{each}} each使用

    <!DOCTYPE html><html><head>    <script src="Scripts/jquery-1.6.2.min.js&qu ...

  7. 新玩具,React v16.7.0-alpha Hooks

    周五看见React v16.7.0-alpha Hooks,今早起来看见圈里已经刷屏了Hooks,正好周末,正好IG和G2的比赛还没开始,研究下... 刚刚接触react时候非常喜欢用函数式组件,因为 ...

  8. 一张图测试你的Hadoop能力-Hadoop能力测试图谱

    1.引言 看到一张图,关于Hadoop技术框架的图,基本上涉及到Hadoop当前应用的主要领域,感觉可以作为测试Hadoop开发人员当前能力和水平的比较好的一个工具,特此分享给大家.如果你能够明白说出 ...

  9. 1115 Counting Nodes in a BST (30 分)

    1115 Counting Nodes in a BST (30 分) A Binary Search Tree (BST) is recursively defined as a binary tr ...

  10. python3 tkinter

    https://morvanzhou.github.io/tutorials/python-basic/tkinter/ 李导师推荐的.非常感谢.非常棒的视频教程!!! 只不过里面的教程视频是yout ...