我想使用node.js發送http請求。我做的:Node.js中的URL分量編碼
http = require('http');
var options = {
host: 'www.mainsms.ru',
path: '/api/mainsms/message/send?project='+project+'&sender='+sender+'&message='+message+'&recipients='+from+'&sign='+sign
};
http.get(options, function(res) {
console.log('STATUS: ' + res.statusCode);
console.log('HEADERS: ' + JSON.stringify(res.headers));
}).on('error', function(e) {
console.log('ERROR: ' + e.message);
});
當我path
這樣的:
/api/mainsms/message/send?project=geoMessage&sender=gis&message=tester_response&recipients=79089145***&sign=2c4135e0f84d2c535846db17b1cec3c6
工作。但是當message
參數包含任何空格時,例如tester response
全部打破。並在控制檯我看到http使用此網址:
/api/mainsms/message/send?project=geoMessage&sender=gis&message=tester
如何發送空格。或者我不能在URL中使用空格?
您需要進行網址編碼。 – thefourtheye
@thefourtheeye:你可以給任何例子或鏈接閱讀? –
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent and http://nodejs.org/api/querystring.html – thefourtheye