如何使用 Node.JS 向 Ghostbin 发出 POST 请求?

APixel 视觉效果

我正在尝试通过 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 的文档,我有什么遗漏吗?

阿里夫汗

你几乎是对的,但你需要将数据传递给formkey(就像你在 #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] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

使用Ajax向Node.js服务器发出POST请求

R 如何向 MongoDB 发出 POST 请求

如何在node.js中发出HTTP POST请求?

无法使用node.js和“请求”模块向UTF-8链接发出请求

使用 Python 请求向本地主机发出 POST 请求

向Chef发出POST请求

在Express.js上使用Axios向Spotify API发出POST请求时出现错误400

如何使用 Node.js 发出 https post 请求(需要授权)

从node.js向WMATA API发出获取请求

向Node.js中的JSON API发出GET请求?

如何向本地托管的node.js服务器发出jQuery请求?

如何从 angular 向 node.js 发出 http.get() 请求?

如何从前端向Spring发出HTTP POST请求?

React Hooks:如何向服务器发出POST请求

如何向 PHP 服务器发出 post 请求

在iOS中使用NSURLSession向.ts文件发出POST请求

在node.js中,我正在发出一个POST请求,在接收到来自POST请求的响应之前,该函数正在向端点发送空间

如何从节点 JS 向 Spring Boot 发出多部分请求?

如何通过在 Firefox 中 fetch js 向 API 发出请求?

如何仅在需要时向 MirajeJS js 发出请求

向Web服务发出POST请求

从 NodeJS 向 Amazon Lex 发出 POST 请求

向Google表单发出POST请求

从独立的 React 向 Django 发出 POST 请求

向第三方API Node.js发出多个请求后如何发送响应

如何使用TcpClient向网站发出请求

如何使用Scribe通过POST向自定义API发出OAuth2授权请求

如何使用ESP8266正确向IFTTT Webhook服务发出POST请求?

我应该如何使用 Axios (React) 向这个 url 发出 post 请求