【发布时间】:2017-05-03 13:18:27
【问题描述】:
我认为使用 NPM 之外的模块之一应该相当容易,但我尝试了两个不同的模块,据我所知,它们都发送没有附加标签的 URL。
网址是:https://safebooru.org/index.php?page=dapi&s=post&q=index 而需要发送的是pid、limit和tags。
但是我一直收到的结果好像我只发送了'https://safebooru.org/index.php?page=dapi&s=post&q=index'
而不是说
'https://safebooru.org/index.php?page=dapi&s=post&q=index&pid=1&limit=10&tags=brown_hair'
请。是否有一个模块可以按预期发送这个 dang 请求,而不仅仅是提供的基本 URL?
我尝试的模块是“请求”和“超级代理”,我是通过 stackoverflow 上的类似问题得到的。
const rp = require("request")
const sa = require("superagent");
class SafebooruGetter {
constructor(data){
//none
}
get(limit, page, tags, callback){
var results;
sa.post('https://safebooru.org/index.php?page=dapi&s=post&q=index')
.send({limit: limit, pid: page, tags: tags})
.end(function(err, res){
if(err)
console.log(err);
else
callback(res);
});
}
get2(limit, page, tags){
var options = {
method: 'POST',
url: 'https://safebooru.org/index.php?page=dapi&s=post&q=index',
form: {
"limit": limit,
"pid": page,
"tags": tags,
},
headers: {
'User-Agent': 'Super Agent/0.0.1',
'Content-Type': 'application/x-www-form-urlencoded'
}
//json: true
};
//console.log(rp(options));
// return rp(options).then((data) => { return (data)});
return rp(options, function(error, response, body){
if(!error && response.statusCode == 200){
console.log(body);
return body;
}
});
}
}
【问题讨论】:
标签: node.js post superagent