我试图将用户添加到我的订阅者列表中,但是我一直在发送请求时遇到问题。无论我选择哪种方法(curl,request,http),我都会遇到错误。这个错误似乎总是对我大喊大叫(但我知道网址有效)。任何帮助将不胜感激
suscribe:function(req,res){
var callback = function(err, response, body){
if(err){
console.log(err);
console.log(url);
res.status(400);
res.send(err);
}else{
res.status(response);
res.send('OK');
}
};
//Builds command
var url = "http://secure.whatcounts.com/bin/api_web";
url += "?cmd=subscribe";
url += "&r=company";
url += "&pwd=pwd";
url +="&list_id=23508";
url += "&data=email,custom_special^" + req.body.email;
url += ",special+text";
request(url.format(url), callback);
},
错误
TypeError: Object http://secure.whatcounts.com/bin/api_web?cmd=subscribe&r=company&pwd=pwd&list_id=23508&data=email,custom_special^pnchappy92@gmail.com,special+text has no method 'format'
at module.exports.suscribe (c:\Users\pchapman\Documents\sparc\controllers\landing.js:36:21)
at Layer.handle [as handle_request] (c:\Users\pchapman\Documents\sparc\node_modules\express\lib\router\layer.js:82:5)
at next (c:\Users\pchapman\Documents\sparc\node_modules\express\lib\router\route.js:110:13)
at Route.dispatch (c:\Users\pchapman\Documents\sparc\node_modules\express\lib\router\route.js:91:3)
at Layer.handle [as handle_request] (c:\Users\pchapman\Documents\sparc\node_modules\express\lib\router\layer.js:82:5)
at c:\Users\pchapman\Documents\sparc\node_modules\express\lib\router\index.js:267:22
at Function.proto.process_params (c:\Users\pchapman\Documents\sparc\node_modules\express\lib\router\index.js:321:12)
at next (c:\Users\pchapman\Documents\sparc\node_modules\express\lib\router\index.js:261:10)
at Object.<anonymous> (c:\Users\pchapman\Documents\sparc\node_modules\express-session\index.js:421:7)
at Object.immediate._onImmediate (timers.js:363:16)
答案 0 :(得分:1)
您使用url
字符串覆盖url
模块。只需使用不同的变量名称即可:
//Builds command
var urlstr = "http://secure.whatcounts.com/bin/api_web";
urlstr += "?cmd=subscribe";
urlstr += "&r=company";
urlstr += "&pwd=pwd";
urlstr +="&list_id=23508";
urlstr += "&data=email,custom_special^" + req.body.email;
urlstr += ",special+text";
request(url.format(urlstr), callback);