rest - 使用微控制器/明文预编码的 POST 字符串制作 HTTP POST (REST API)
问题描述
我正在开发一个微控制器与 Web 服务器接口的项目。它非常接近裸机,因此该项目不允许使用任何库或任何东西。
我已经能够很好地执行 GET 请求,像这样为我的微编码字符串:
"GET /rest/foo/_attribute/bar/ HTTP/1.1\r\n\r\n"
返回的数据看起来像这样:
HTTP/1.1 200 OK
Date: Thu, 01 Jan 1970 00:01:06 GMT
Connection: Keep-Alive
Set-Cookie: rtlt4session=1; path=/
Cache-control: no-cache
Content-Type: application/json
Content-Length: 70
{"bar":"factory":"Attribute","factoryType":"bool","value":true}}`
但是,我在发出 POST 请求时遇到问题。我试过这个:
"POST /rest/foo/_attribute/bar/ HTTP/1.1\r\n\r\n{"bar":"factory":"Attribute","factoryType":"bool","value":false}}\r\n\r\n"
但它不能正常工作,设备通常会等待一段时间然后响应 400 Bad Request 消息,说明缺少 REST 更新内容,如下图所示:
HTTP/1.1 400 Bad Request
Date: Thu, 01 Jan 1970 00:07:23 GMT
Connection: Keep-Alive
Set-Cookie: rtlt4session=3; path=/
Cache-control: no-cache
Content-Type: text/plain
Content-Length: 84
Missing REST update content on a POST for REST URI '/rest/foo/_attribute/bar'
任何建议或意见,将不胜感激。
解决方案
推荐阅读
- c++ - std::move on boost::asio::ip::tcp::socket
- python - 对于使用的每个 Scipy 函数,Spyder 都会引发 DeprecationWarning
- laravel - [Route: berita.update] 缺少必需的参数
- javascript - 正则表达式(太多?)很多情况
- powershell - 通过切片现有的arraylist创建Arraylist的Arraylist
- angular - 如何在生产中访问 Angular 应用程序
- latex - 在投影仪和 \pause 中的同一张幻灯片上参考
- javascript - 无法使用 JQUERY 嵌套 div 元素
- python-3.x - dropna() 在给定阈值的情况下不适用于轴 = 1
- algorithm - 了解大 O 复杂性