nodejs http.requset options传字符串参数
来源:互联网 发布:淘宝卖家如何设置佣金 编辑:程序博客网 时间:2024/06/03 20:10
今天在工作中碰到使用nodejs http.request(options, callback)传多个参数,并且参数含空格的情况怎么传都失败,发现是用浏览器就成功,打印出来浏览器传输是encode过得,于是使用js的encodeURIcomponet(str),加密再传参果断成功,记录下来方便查阅;
var content = "this is a test";
var contact = "test@test.cn"
param = {"id":21}+','+contact+','+conten
var options = {
host: '127.0.0.1', //server adderss
port: 3000, //server port
method: method,
path: service+param //service and argument
};
var req = http.request(options, function(res) {});
解决方法:
param = JSON.stringify(user) + ',' + encodeURIComponent(contact) + ',' + encodeURIComponent(context);
附各种语言urlencode方法:
一.JavaScript:
编码:encodeURIComponent(URIString)
解码:
decodeURIComponent(encodedURIString)
二.ASP:
编码:Server.urlencode(str)
解码:
无
三.Asp.Net
编码:HttpUtility.Urlencode(str)
解码:HttpUtility.UrlDecode(str)
四.Php
编码:
urlencode(str)
解码:urldecode(str)
五.Java
编码:
java.net.URLEncode.encode(str)
解码:
java.net.URLDecoder.decode(str)
0 0
- nodejs http.requset options传字符串参数
- HTTP协议(Requset、Response)
- NodeJs中的express框架获取http参数
- nodejs http.request 参数格式之querystring
- Android(Java):http options
- node http.get options
- $http请求之options
- NodeJS的Express框架获取Http请求参数
- nodejs--http
- nodejs-http
- NodeJS-http
- requset&response
- HTTP的请求方法OPTIONS
- HTTP的请求方法OPTIONS
- HTTP的请求方法OPTIONS
- HTTP的请求方法OPTIONS
- HTTP的请求方法OPTIONS
- HTTP的请求方法OPTIONS
- Android开发开源源代码
- git 把文件从 版本管理中移除
- 理解 Android 的 ONE_SHOT_MAKEFILE
- Ext空间重置
- ZOJ Problem Set - 3822Domination(DP)
- nodejs http.requset options传字符串参数
- DWR框架中WebContext与WebContextFactory类
- github常见操作和常见错误!错误提示:fatal: remote origin already exists.
- 总也赶不上时髦!
- Ubuntu安装配置Mysql
- coreos 创建使用密钥登陆的ubuntu 基础镜像
- 吉布斯采样(Gibbs Sampling)
- 黑马程序员---入学测试题
- HTTPS和证书原理