node.js - 带有 node.js 和请求库的 HTTP POST 没有输出任何内容
问题描述
我只是在测试我对网站的 POST 请求是否有效,但它没有输出任何内容。当我使用 RunKit 时,它会显示输出,但不会在我的 powershell 中显示。我做错了什么还是没有输出?我怎样才能让它显示输出?这是我的代码:
var request = require('request');
request.post(
'My_API_URL',
{ json: { "text":"this is my text" } },
function (error, response, body) {
console.log(body);
}
);
解决方案
检查此链接。您应该像这样发布请求:
var request = require('request');
var body = JSON.stringify({
client_id: '0123456789abcdef',
client_secret: 'secret',
code: 'abcdef'
});
request.post({
url: 'https://postman-echo.com/post',
body: body,
headers: {
'Content-Type': 'application/json'
}},
function (error, response, body) {
console.log(body);
}
);
推荐阅读
- python - 如何删除数据框中的重复值和计算经过的时间?
- css - 在 Wordpress 中,mapbox 徽标在网格之外展开
- sql - SQL:检查一个数字是否在多个范围的范围内
- c# - Xamarin SQLite 数据库检查
- javascript - 从某个位置获取半径范围内的城市(Google Map API)
- python - SQL Server 连接 - 适用于 pyodbc,但不适用于 SQLAlchemy
- python - postgres10 的 psycopg2 编码错误
- swift - 如何实现垂直标签可可应用程序
- javascript - 如何在 ReactJs 中呈现 jsx 元素数组
- python-3.x - 如何在没有 python shell 的情况下获取键盘输入