Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/251.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过arduino向PHP文件发送POST请求_Php_Post_Arduino_Httpclient - Fatal编程技术网

通过arduino向PHP文件发送POST请求

通过arduino向PHP文件发送POST请求,php,post,arduino,httpclient,Php,Post,Arduino,Httpclient,我正试图发送一个温度读数到我的网站上的一个php文件。但是,温度变量似乎没有传递。下面我使用以下Arduino代码: 包括 包括 定义服务器IP XXX.XX.XXX.XX ifndef STASSID 定义STASSID XXX 定义STAPSK XXX 恩迪夫 无效设置{ 从15200年开始; Serial.println;Serial.println;Serial.println; WiFi.beginSTASSID,斯塔普斯克; 而WiFi.status!=WLU已连接{delay50

我正试图发送一个温度读数到我的网站上的一个php文件。但是,温度变量似乎没有传递。下面我使用以下Arduino代码:

包括 包括 定义服务器IP XXX.XX.XXX.XX ifndef STASSID 定义STASSID XXX 定义STAPSK XXX 恩迪夫 无效设置{ 从15200年开始; Serial.println;Serial.println;Serial.println; WiFi.beginSTASSID,斯塔普斯克; 而WiFi.status!=WLU已连接{delay500;Serial.print.} Serial.println;Serial.printConnected!IP地址:;Serial.printlnWiFi.localIP; } 空穴环{ 如果WiFi.status==WL\U已连接{ 无线客户端; HTTPClient-http; 串行。打印[HTTP]开始…\n; http.beginclient,http://SERVER\u IP/device.php;//http http.addHeaderContent-Type,application/json; 串行。打印[HTTP]POST…\n; int httpCode=http.POST{\temp\:\15\}; 如果httpCode>0{ Serial.printf[HTTP]POST…代码:%d\n,httpCode; 如果httpCode==HTTP\u CODE\u正常{ const String&payload=http.getString; Serial.println收到的有效负载:\n; } }否则{ Serial.printf[HTTP]POST…失败,错误:%s\n,HTTP.errorToStringttpCode.c_str; } http.end; } 延迟10万; } 根据切线垂直注释的解决方案是将内容类型标题更改为

    http.addHeader("Content-Type", "application/x-www-form-urlencoded");
并将数据发布到

    int httpCode = http.POST("temp=15");
根据切线垂直注释的解决方案是将内容类型标题更改为

    http.addHeader("Content-Type", "application/x-www-form-urlencoded");
并将数据发布到

    int httpCode = http.POST("temp=15");

在PHP中,执行var_dump$\u POST;在标题后面查看输出包含的内容。@PaulT.it显示为nullWell,这解释了注意事项。我必须检查一下使用情况,这篇文章显然没有达到预期的效果。对此不确定,但是。。。您正在发送JSON编码的数据,但PHP需要来自帖子的表单编码数据,因此请更改内容类型header application/x-www-form-urlencoded,并将数据更改为temp=15。将15更改为所需的任何变量。@TangentiallyVertical我尝试了int-httpCode=http.POST?temp=15,但也不起作用。在PHP中,执行var\u dump$\u POST;在标题后面查看输出包含的内容。@PaulT.it显示为nullWell,这解释了注意事项。我必须检查一下使用情况,这篇文章显然没有达到预期的效果。对此不确定,但是。。。您正在发送JSON编码的数据,但PHP需要来自帖子的表单编码数据,因此请更改内容类型header application/x-www-form-urlencoded,并将数据更改为temp=15。将15更改为所需的任何变量。@TangentiallyVertical我尝试了int-httpCode=http.POST?temp=15,但也不起作用。