node.js - 使用 NodeJS 发送 post 请求
问题描述
我正在尝试向安装在 pi 上的服务发送发布请求。这是我正在使用的应用程序:
const http = require('http')
const data = JSON.stringify({
Name:"MYONE",
})
const options = {
hostname: 'http://127.0.0.1',
port: 11555,
PATH:'/api/config',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': data.length
}
}
const req = http.request(options, (res) => {
console.log(`statusCode: ${res.statusCode}`)
res.on('data', (d) => {
process.stdout.write(d)
})
})
req.on('error', (error) => {
console.error(error)
})
req.write(data)
req.end()
该应用程序应更改设备的名称。根据文档,返回状态应为 200,以防“一切顺利”运行该应用程序我得到以下信息:
node app.js
statusCode: 200
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
<html>
<head>
<title>Changing device name </title>
<link rel="stylesheet" type="text/css" href="/style.css" />
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
</head>
<frameset rows="52,20,16,*" frameborder="0" framespacing="0" border="0">
<frameset cols="*,771,*" frameborder="0" framespacing="0" border="0">
<frame src="/menu?logo=b" noresize scrolling="no" marginheight="0" marginwidth="0" framespacing="0" frameborder="0" border="0">
<frame name="toplogo" src="/menu?logo=t" noresize scrolling="no" marginheight="0" marginwidth="0" framespacing="0" frameborder="0" border="0">
<frame src="/white.html" noresize scrolling="no" marginheight="0" marginwidth="0" framespacing="0" frameborder="0" border="0">
</frameset>
<frame name="navibar" src="/menu" noresize scrolling="no" marginheight="0" marginwidth="0" framespacing="0" frameborder="0" border="0">
<frame name="submenu" src="/grey.html" noresize scrolling="no" marginheight="0" marginwidth="0" framespacing="0" frameborder="0" border="0">
<frame name="content" src="/menu?info=Browser" marginheight="0" marginwidth="0" framespacing="0" frameborder="0" border="0">
<noframes>You must use a browser with frame support to see this page.</noframes>
</frameset>
</html>
最后我得到状态码 200 但设备名称没有改变。知道我在这里缺少什么吗?我希望我可以提供有关该服务的更多信息,但我没有任何信息。
解决方案
推荐阅读
- rust - Rust 中隐藏的代理和实现模式?
- java - 在 Android 中共享自定义文本
- reactjs - 如何实现卡片媒体内的图片会以某种方式弹出或悬停在上方的样式?
- git - 如何删除 git 较旧的提交并仅保留最新的提交?
- android - 错误:不兼容的类型:当我运行 @Test 注释时,NonExistentClass 无法转换为注释 @error.NonExistentClass()
- flutter - Flutter 在后台离线推送通知
- dependencies - python3.9-dev 依赖错误 deadsnakes Mint 20
- python - Slurm 作业处于运行状态但不产生任何结果
- powershell - 带有 PowerShell 的 SAP .Net 连接器:在 SAP 系统中打开 PDF
- sql - 如何使用更改表查询在 AWS Redshift 中添加多列