C文件:
#include <Ethernet.h>
#include <SPI.h>
byte mac[] = { 0x90,0xA2,0xDA,0x00,0x55,0x8D}; //Replace with your Ethernet shield MAC
EthernetClient client;
void setup()
{
Serial.begin(9600);
Ethernet.begin(mac);
delay(1000);
Serial.println("connecting...");
}
void loop(){
String data;
data+="";
data+="data=12.7%2C0%2C50"; // Use HTML encoding for comma's
data+="&submit=Submit"; // Submitting data
if (client.connect("www.your-website.com",80)) {
Serial.println("connected");
client.println("POST /pageThatTakesPostData.php HTTP/1.1");
client.println("Host: www.your-website.com");
client.println("Content-Type: application/x-www-form-urlencoded");
client.println("Connection: close");
client.print("Content-Length: ");
client.println(data.length());
client.println();
client.print(data);
client.println();
//Prints your post request out for debugging
Serial.println("POST /pageThatTakesPostData.php HTTP/1.1");
Serial.println("Host: www.your-website.com");
Serial.println("Content-Type: application/x-www-form-urlencoded");
Serial.println("Connection: close");
Serial.print("Content-Length: ");
Serial.println(data.length());
Serial.println();
Serial.print(data);
Serial.println();
}
delay(2000);
if (client.connected()) {
Serial.println();
Serial.println("disconnecting.");
client.stop();
}
}
PHP文件:
<?php
header("Content-type: text/html");
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
if(strlen($_POST["data"]) > 1 )
{
echo "1"; // if it displays 1 it worked
}
if(strlen($_POST["submit"]) > 1 )
{
echo "1"; // if it displays 1 it worked
}
?>
HTML文件:
<html>
<body>
<FORM action="abovePage.php" method="POST">
<P>
<LABEL for="firstname">Data To Send:</LABEL>
<INPUT type="text" name="data"><BR>
<INPUT type="submit" value="Submit">
</P>
</FORM>
</body>
</html>
请问以上这3个文件如何一起使用?是在Macbook ios系统下的,其实我是想通过Arduino监测ID,然后上传到网站上以供搜查。
麻烦各位大大帮忙,求助!
|