首页 > nodejs 发起 post 请求 提交数据转为 gbk 编码

nodejs 发起 post 请求 提交数据转为 gbk 编码

go 实现

在用 go 语言提交的时候可以这么转

    enc := mahonia.NewEncoder("gbk")
    msg = enc.ConvertString('你好你好')

nodejs 实现

由于提交服务器只接受 gbk 编码

 var postData = querystring.stringify({
       'user' : user,
       'msg' : '你好你好',
      });

  var options = {
    hostname: '172.20.7.29',
    port: 8012,
    path: '/',
    method: 'POST',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
      'Content-Length': Buffer.byteLength(postData)
    }
  };

如果把 以上的 msg 转为 gbk 编码呢


使用request请求post,如何以GB2312方式请求?

【热门文章】
【热门文章】