nodejs http post 请求带参数
自己开发的公众号,可以领取淘宝内部优惠券

// We need this to build our post string
var querystring = require('querystring');
var http = require('http');
var fs = require('fs'); function PostCode(codestring) {
// Build the post string from an object
var post_data = querystring.stringify({
'compilation_level' : 'ADVANCED_OPTIMIZATIONS',
'output_format': 'json',
'output_info': 'compiled_code',
'warning_level' : 'QUIET',
'js_code' : codestring
}); // An object of options to indicate where to post to
var post_options = {
host: 'closure-compiler.appspot.com',
port: '80',
path: '/compile',
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': Buffer.byteLength(post_data)
}
}; // Set up the request
var post_req = http.request(post_options, function(res) {
res.setEncoding('utf8');
res.on('data', function (chunk) {
console.log('Response: ' + chunk);
});
}); // post the data
post_req.write(post_data);
post_req.end(); } // This is an async file read
fs.readFile('LinkedList.js', 'utf-8', function (err, data) {
if (err) {
// If this were just a small part of the application, you would
// want to handle this differently, maybe throwing an exception
// for the caller to handle. Since the file is absolutely essential
// to the program's functionality, we're going to exit with a fatal
// error instead.
console.log("FATAL An error occurred trying to read in the file: " + err);
process.exit(-2);
}
// Make sure there's data before we post it
if(data) {
PostCode(data);
}
else {
console.log("No data to post");
process.exit(-1);
}
});
nodejs http post 请求带参数的更多相关文章
- httpclient post请求带参数返回数据乱码问题解决
客户端代码: //带参数的post请求 @Test public void doPostWithParam() throws Exception { CloseableHttpClient httpC ...
- perl post 请求带参数
my $url='https://wenjinbao.winfae.com/business/dispatch_post.do?action=submitAdminLogin'; my $res ...
- Java后端发出post请求带参数并接收返回的json
核心代码: 参数格式: “key1=value1&key2=value2” /*** sendUrl (远程请求的URL)* param (远程请求参数)* JSONObject ...
- java get请求带参数报错 java.io.IOException: Server returned HTTP response code: 400 for URL
解决方案 在使用JAVA发起http请求的时候,经常会遇到这个错误,我们copy请求地址在浏览器中运行的时候又是正常运行的,造成这个错误的原因主要是因为请求的URL中包含空格,这个时候我们要使用URL ...
- 【笔记】Asp.Net WebApi对js POST带参数跨域请求的支持方案
先说下需求:在原来的WebApi项目中增加对js跨域的请求支持,请求方式:以POST为主,webapi路由规则根据原项目需求修改如下: public static void Register(Http ...
- 微信小程序之跳转、请求、带参数请求小例子
wx.request(OBJECT) wx.request发起的是 HTTPS 请求.一个微信小程序,同时只能有5个网络请求连接. 具体参数说明参看微信小程序官方文档-发起请求. 例: //当页面加载 ...
- Spring MVC中forward请求转发2种方式(带参数)
Spring MVC中forward请求转发2种方式(带参数) http://www.51gjie.com/javaweb/956.html
- angular4 get,post请求(带参数,与不带参数)
一:在app.module.ts引入HttpMoudle import { BrowserModule } from '@angular/platform-browser'; import { Htt ...
- httpclient post请求例子(无参数名与带参数名的例子),多线程并发处理
版本:4.1 带参数名的情况 HttpClient httpClient = new DefaultHttpClient(); HttpPost httpPost = new HttpPost(url ...
随机推荐
- Linux环境JDK安装
Java的编程离不开jdk,今天本文主要讲下Linux下的JDK安装与配置 1.卸载Linux自带的JDK #检测jdk安装包 [root@localhost ~]# rpm -qa | grep j ...
- JQuery常用知识点及示例
1.JQuery 名称解释 JQuery是封装了常用JS操作函数的一个库文件JQuery = Javascript + Query (查询)Jquery意思即指: 强大的DOM节点查询 2.官网:ht ...
- HTTP的请求方法OPTIONS
HTTP请求方法并不是只有GET和POST,只是最常用的.据RFC2616标准(现行的HTTP/1.1)得知,通常有以下8种方法:OPTIONS.GET.HEAD.POST.PUT.DELETE.TR ...
- PHP 常用的header头部定义汇总
http://www.jb51.net/article/68159.htm
- 面试官最爱的volatile关键字
在Java相关的岗位面试中,很多面试官都喜欢考察面试者对Java并发的了解程度,而以volatile关键字作为一个小的切入点,往往可以一问到底,把Java内存模型(JMM),Java并发编程的一些特性 ...
- OpenCV3.0 HDR(高动态范围)示例代码以及用法
OpenCV 3.0以及以后版本集成了HDR算法,样例代码的路径为: .\sources\samples\cpp\tutorial_code\photo\hdr_imaging.cpp. 实现算法的参 ...
- sql 时间转换问题 from_unixtime() UNIX_TIMESTAMP()
http://blog.csdn.net/test_soy/article/details/50328367 from_unixtime()是MySQL里的时间函数 date为需要处理的参数(该参数是 ...
- 什么是bgp线路
https://www.douban.com/note/319956581/ BGP(边界网关协议)主要用于互联网AS(自治系统)之间的互联,BGP的最主要功能在于控制路由的传播和选择最好的路由.中国 ...
- RocketMQ-quickstart(批量消费问题)
基本概念: Producer:消息生产者,负责生产消息,一般由业务系统负责生产消息. Consumer:消息消费者,负责消费消息,一般是后台系统负责异步消费. Push Consumer:Consum ...
- 重温吕鑫MFC教学视频(一)
重温吕鑫MFC教学视频(一)1. picture控件的使用,可以显示icon和bitmap2. WM_Create窗口的创建3. 创建的销毁消息及区别WM_SYSCOMMAND WM_CLOSE WM ...