事情是這個樣子的:老大今天丟的程式碼,有一段沒看懂,又沒臉問人家,只好挺著粉嫩嫩的老不要臉來問大家:
router.post('/my_single_article', function(req, res, next) {
var request = require('./utils/cookie-request').init(req,global.host);
request.post(global.config.api('my_single_article'),
{
form: req.body,
json:false
},
function(error, response, body){
var result = JSON.parse(body);
console.log(result+'12324');
console.log(global.host);
res.render('tpl/my_single_article_list',
{
page:result.data,
});
}
);
});
裡面的這句話 不是很懂
var request = require('./utils/cookie-request').init(req,global.host);
引用的cookie-request區塊如下:
var request = require('request');
var format = require("string-template");
exports.init = function(req, domain){
// 保持与请求接口的session一致
var url = domain || "http://album.laifuzi.cn";
var j = request.jar();
if(req && req.cookies) {
for(x in req.cookies){
var cookie = request.cookie(format('{0}={1}', x, req.cookies[x]));
j.setCookie(cookie, url);
}
}
return request.defaults({jar:j});
};
請各路大神不吝賜教 拜託啦
這段沒看懂吧?
format('{0}={1}={2}',1,2,3)
=>1=2=3
,格式化處理而已雷雷
雷雷