我正在尝试通过 Node.JS 及其NPM 模块向Ghostbin发送 POST 请求request
。这是我的代码的样子:
尝试 1:
reqest.post({
url: "https://ghostbin.com/paste/new",
text: "test post"
}, function (err, res, body) {
console.log(res)
})
尝试 2:
reqest.post({
url: "https://ghostbin.com/paste/new",
text: "test post",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
"Content-Length": 9
}
}, function (err, res, body) {
console.log(res)
})
尝试 3:
reqest.post("https://ghostbin.com/paste/new", {form: {text: "test post"}}, function (err, res, body) {
console.log(res)
})
所有这些尝试都以日志记录告终:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">\n<html><head>\n<title>406 Not Acceptable</title>\n</head><body>\n<h1>Not Acceptable</h1>\n<p>An appropriate representation of the requested resource /paste/new could not be found on this server.</p>\n<hr>\n<address>Apache/2.4.18 (Ubuntu) Server at ghostbin.com Port 443</address>\n</body></html>
关于request
库或Ghostbin API 的文档,我有什么遗漏吗?
你几乎是对的,但你需要将数据传递给form
key(就像你在 #3 中所做的那样)并user-agent
按照 api 中提到的那样传入header
reqest.post({
url: "https://ghostbin.com/paste/new",
form: {
text: "test post"
},
headers: {
'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36'
}
}, function (err, res, body) {
console.log(res)
})
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句