php - Apache http 服务器回复 418 ("I' m a teapot") - json 参数,使用来自 arduino 的 PUT 的 TCP 请求

标签 php json apache http arduino

我正在尝试使用来自 arduino 的 PUT 方法将数据(json 格式的字符串)作为参数发送到 Apache HTTP 服务器。服务器的回复是418茶壶回复。 这是我第一个使用 TCP 请求、http、php 的项目——所以我在这方面没有扎实的背景。

字符串:

{%221%22:%22FE005F719444%22,%222%22:%22ooooooooooxo%22,%223%22:%22ooooooooooxo%22}

TCP请求:

PUT /proxyJson/index.php/?YOUR_data={%221%22:%22FE005F719444%22,%222%22:%22ooooooooooxo%22,%223%22:%22ooooooooooxo%22} HTTP/1.1 200 OK
Host: 192.168.xx.xxx
User-Agent: 192.168.xx.xxy
Content-Type: text/html; charset=iso-8859-1
Content-Length: 0
Connection: close

Apache 访问日志:

192.168.xx.xxy - - [27/Dec/2016:19:50:22 +0200] "GET /proxyJson/index.php/?YOUR_data=    {%221%22:%22FE005F719444%22,%222%22:%22ooooooooooxo%22,%223%22:%22ooooooooooxo%22} HTTP/1.1" 400 226 

如果直接在浏览器中输入数据,脚本就可以正常工作。

php script result

我错过了什么? 感谢回复和支持。

乔治

最佳答案

您的请求有误。 第一行应该是:

PUT /proxyJson/index.php/?YOUR_data={%221%22:%22FE005F719444%22,%222%22:%22ooooooooooxo%22,%223%22:%22ooooooooooxo%22} HTTP/1.1

没有:

200 OK

此外,我建议在请求正文中发送您的数据。 所以你的要求是:

PUT /proxyJson/index.php HTTP/1.1
Host: 192.168.xx.xxx
User-Agent: 192.168.xx.xxy
Content-Type: application/json
Content-Length: 58
Connection: close

{"1":"FE005F719444","2":"ooooooooooxo","3":"ooooooooooxo"}

这就是 Content-TypeContent-Length header 的目的。

关于php - Apache http 服务器回复 418 ("I' m a teapot") - json 参数,使用来自 arduino 的 PUT 的 TCP 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41350385/

相关文章:

php - 如何在表格的所有列中进行搜索?

java - java读取json数据

apache solr 作为服务托管

php - 根据输出格式编写查询

php - Fusebox 框架的 future

ios - Swift 中的 JSONModel 问题

java - Apache Axis : no containing element

python - (2002, "Can' t 通过套接字 '/var/lib/mysql/mysql.sock' (2) 连接到本地 MySQL 服务器”)

PHP MySQL : Data is getting reset to 0's when trying to edit

javascript - 将数据从 MySQL 存储到 PHP 数组并以 JSON 返回