URL component encoding in Node.js

前端 未结 3 1884
攒了一身酷
攒了一身酷 2020-12-30 00:30

I want to send http request using node.js. I do:

http = require(\'http\');

var options = {
    host: \'www.mainsms.ru\',
    path: \'/api/mainsms/message/se         


        
3条回答
  •  隐瞒了意图╮
    2020-12-30 00:50

    The best way is to use the native module QueryString :

    var qs = require('querystring');
    console.log(qs.escape('Hello $ é " \' & ='));
    // 'Hello%20%24%20%C3%A9%20%22%20\'%20%26%20%3D'
    

    This is a native module, so you don't have to npm install anything.

提交回复
热议问题