Arduino获取请求和主机服务器?

时间:2013-11-26 01:56:12

标签: php post arduino

我想让我的arduino运行一个Web服务器,但也会不时发布一个变量。我有以下代码:

client.println("HTTP/1.1 200 OK");
client.println("Host: joeybabcock.me");    //
client.print("GET /writetemplocalserv.php?t0=");     
client.println("Content-Type: text/html");
client.println(sensorValue);
client.println("Connnection: close");

以及这里的整个代码(如果你不得不这样,那么只需查看一下。):http://pastebin.com/TXPccYs3 这不会发布变量。如果在网络浏览器中访问完全相同的网址,它确实有效。

1 个答案:

答案 0 :(得分:3)

RFC 2161,定义 / 1.1,在编写Web(HTTP)服务器和客户端时必须始终遵循。

你的代码很乱:

client.println("HTTP/1.1 200 OK"); //Response
client.println("Host: joeybabcock.me"); //Response/request
client.print("GET /writetemplocalserv.php?t0="); //Request
client.println("Content-Type: text/html"); //Response
client.println(sensorValue); //Probably invalid...
client.println("Connnection: close"); //Request/Response

如果您想要请求,请以非常非常简短的方式:

client.print("GET /writetemplocalserv.php?t0=");
client.print(sensorValue);
client.println(" HTTP/1.1");
client.println("Host: joeybabcock.me");
client.println(""); //mandatory blank line

回复:

client.println("HTTP/1.1 200 OK");
client.println("Host: joeybabcock.me");
client.println("Content-Type: text/html");
client.println("Connection: close");
client.println("");
client.println("body data");
...

同样,任何HTTP请求/响应都必须遵循RFC 2161