Post请求

var http=require('http');
var qs=require('querystring'); var post_data={a:123,time:new Date().getTime()};//这是需要提交的数据
var content=qs.stringify(post_data); var options = {
host: '127.0.0.1',
port: 8080,
path: '/admin',
method: 'POST',
headers:{
'Content-Type':'application/x-www-form-urlencoded',//post请求需要设置的type值
'Content-Length':content.length
}
};
console.log("post options:\n",options);
console.log("content:",content);
console.log("\n");
var a=''
var req = http.request(options, function(res) {
console.log("statusCode: ", res.statusCode);
console.log("headers: ", res.headers);
var _data='';
res.on('data', function(chunk){
_data += chunk;
a=chunk;
});
res.on('end', function(){
console.log("\n--->>\nresult:",_data)
});
}); req.write(content);
req.end(); http.createServer(function (request, response) { // 发送 HTTP 头部
// HTTP 状态值: 200 : OK
// 内容类型: text/plain
response.writeHead(200, {'Content-Type': 'text/plain'});
response.write(a)
// 发送响应数据 "Hello World"
response.end('Hello World\n');
}).listen(8888);

  在服务中解析Post请求参数

var express=require('express');
var app=express();
var bodyParser = require("body-parser");
app.use(bodyParser.urlencoded({ extended: false }));
app.post('/admin',(req,res)=>{
console.log(req)
var data={
code:200,
msg:'success'
}
res.json(data);
}) app.listen(8080,()=>{ console.log(8080)
})

  

http.request请求及在node中post请求参数解析的更多相关文章

  1. http请求在asp.net中的请求过程

    当请求一个*.aspx文件的时候,这个请求会被inetinfo.exe进程截获,它判断文件的后缀(aspx)之后,将这个请求转交给 ASPNET_ISAPI.dll,ASPNET_ISAPI.dll会 ...

  2. 0057 Spring MVC如何获取HTTP请求头信息--URL中的动态参数--@RequestHeader--@CookieValue--@PathVariable

    获取HTTP请求头信息 一个HTTP请求除了有参数和实体内容外还有HTTP请求头信息,Spring MVC也可以获取这部分信息 @RequestHeader解可以将请求头信息映射到处理方法的形参上 @ ...

  3. jQuery中$.ajax()方法参数解析

    本文实例为大家讲解了jQuery $.ajax()方法参数,供大家参考,具体内容如下 $.ajax({ url:'test.do', data:{id:123,name:'xiaoming'}, ty ...

  4. struct2中package的参数解析

    struct2框架的核心组件是action和拦截器,它使用包来管理action和拦截器,每个包就是多个action.多个拦截器引用的集合.在struct.xml中,package元素用于定义包的配置, ...

  5. C语言中函数可变参数解析

    大多数时候,函数中形式参数的数目通常是确定的,在调用时要依次给出与形式参数对应的所有实际参数.但在某些情况下希望函数的参数个数可以根据需要确定.典型的例子有 大家熟悉的函数printf().scanf ...

  6. Python 中命令行参数解析工具 docopt 安装和应用

    什么是 docopt? 1.docopt 是一种 Python 编写的命令行执行脚本的交互语言. 它是一种语言! 它是一种语言! 它是一种语言! 2.使用这种语言可以在自己的脚本中,添加一些规则限制. ...

  7. node中https请求 | 实现https的请求,获取图片,然后转成base64字节码

    get请求 下面实现https的请求,获取图片,然后转成base64字节码 this.checkCodeUrl = 'https://www.test.com/kaptcha.jsp'; var ht ...

  8. # node中的url常用方法解析

    url字符串是一个结构化的字符串,由好几个有意义部分组成.我们在工作中不可避免的会用到其中的某个部分,最原始的通过字符串截取和正则匹配的方法难免用起来会不太方便和美观,所以在我们的nodejs中提供了 ...

  9. php curl请求。header头中添加请求信息

    function get_data($key,$authorization,$url){ $headers = array(    'api-key:'.$key,    'authorization ...

随机推荐

  1. WPF文本框只允许输入数字

    XAML代码   < TextBox Height="23" HorizontalAlignment="Left" Margin="100,5, ...

  2. Linux基础二

    linux命令分类 内部命令:属于shell解释器 外部命令:独立于shell解释器 检查命令类型 type:检查命令字的类型 [root@localhost ~]# type ls ls 是 `ls ...

  3. ffmpeg结构体以及函数介绍(二)

    1 avcodec_find_decoder() /** * Find a registered decoder with a matching codec ID. * * @param id Cod ...

  4. error: No curses/termcap library found的解决办法

    mysql版本:5.1.30 已经不记得这次是第几次安装mysql了,遇到这个问题倒是第一次. 之前在tar,./configure,make,make install 经典四步时,从来没有想过其中的 ...

  5. 【dedecms】DEDE列表页调用文章内容第一张图片(非缩略图)方法

    打开 ../ include/ common.func.php 添加代码 //将缩放图转变为文章第一张图片 function firstimg($str_pic) { $str_sub=substr( ...

  6. FusionWidgets之AngularGauge图

    1.设置AngularGauge图的数据源 AngularGauge.xml: <?xml version="1.0" encoding="UTF-8"? ...

  7. freemarker写select组件报错总结(四)

    1.错误描述 <html> <head> <meta http-equiv="content-type" content="text/htm ...

  8. hdu5945 Fxx and game

    单调队列学习 其实和单调栈类似 都是因为有些元素是没有价值的可以舍去 #include<bits/stdc++.h> using namespace std; #define sz(X) ...

  9. poj1417菜鸡的详细题解(希望能帮助到和我一样陷于本题的新手)

    题意太麻烦就偷懒转载他人的题意..... 题意转载自http://blog.csdn.net/acm_cxlove/article/details/7854526       by---cxlove ...

  10. How to verify Certificate Pinning?

    Some friends of mine they worry about the risk of Man-in-the-middle so they ask me how to verify the ...