要查看Arduino发送到PHP表单的HTTP POST值,可以按照以下步骤进行:
#include <WiFi.h>
#include <HTTPClient.h>
const char* ssid = "your_SSID";
const char* password = "your_PASSWORD";
void setup() {
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
}
void loop() {
if (WiFi.status() == WL_CONNECTED) {
HTTPClient http;
http.begin("http://your_php_form_url"); // 替换为你的PHP表单URL
http.addHeader("Content-Type", "application/x-www-form-urlencoded");
String postData = "param1=value1¶m2=value2"; // 替换为你的POST参数和数值
int httpResponseCode = http.POST(postData);
if (httpResponseCode > 0) {
String response = http.getString();
Serial.println(httpResponseCode);
Serial.println(response);
} else {
Serial.print("Error code: ");
Serial.println(httpResponseCode);
}
http.end();
}
delay(5000); // 每隔5秒发送一次POST请求
}
$_POST
全局变量来获取POST参数的值。例如:<?php
$param1 = $_POST['param1'];
$param2 = $_POST['param2'];
echo "Received POST values: param1 = $param1, param2 = $param2";
?>
这样,你就可以通过Arduino发送到PHP表单的HTTP POST值,并在串口监视器中查看到相应的结果。
请注意,以上步骤中的代码和示例仅供参考,实际情况可能因你的具体需求和环境而有所不同。
领取专属 10元无门槛券
手把手带您无忧上云