本站改版新增arduino频道
arduino post 提交php
<?php if ($_SERVER["REQUEST_METHOD"] == "POST") { $apiKey = $_POST["apiKey"]; $field1 = $_POST["field1"]; // 获取 POST 提交的数据 $field2 = $_POST["field2"]; $field3 = $_POST["field3"]; file_put_contents("data.txt", $apiKey.'\n'.$field1.'\n'.$field2.'\n'.$field3); // 将数据保存到 txt 文件 } ?> #include <WiFi.h> const char* apiKey = "123456"; const char* ssid = "NBWIFI"; // Enter your WiFi Network's SSID const char* pass = "z7758521"; // Enter your WiFi Network's Password const char* server = "www.api56.com"; WiFiClient client; void setup() { Serial.begin(115200); Serial.println("Connecting to "); Serial.println(ssid); WiFi.begin(ssid, pass); while (WiFi.status() != WL_CONNECTED) { delay(100); Serial.print("*"); } Serial.println(""); Serial.println("WiFi connected"); } void loop() { if (client.connect(server, 80)) { String postStr = apiKey; postStr += "&apiKey="; postStr += String("11111111"); postStr += "&field1="; postStr += String(100); postStr += "&field2="; postStr += String(200); postStr += "&field3="; postStr += String(300); client.print("POST /test.php HTTP/1.1\n"); delay(100); client.print("Host: www.api56.com\n"); delay(100); client.print("Connection: close\n"); delay(100); client.print("X-THINGSPEAKAPIKEY: " + apiKey + "\n"); delay(100); client.print("Content-Type: application/x-www-form-urlencoded\n"); delay(100); client.print("Content-Length: "); delay(100); client.print(postStr.length()); delay(100); client.print("\n\n"); delay(100); client.print(postStr); delay(100); } client.stop(); Serial.println("Sending...."); delay(15000); }
Copyright © 2014 ESP56.com All Rights Reserved
晋ICP备14006235号-22 晋公网安备14108102001165号
执行时间: 0.011314153671265 seconds