我正在使用NodeMCU,并希望将数据记录到我的本地Web2Py服务器。
请求:"http://minion.local:8000/ardulog/default/add/6476366/45643“在浏览器中运行良好,并返回一个记录id。
我的Arduino可以连接到我的服务器,但没有得到任何返回数据、错误或其他信息,并且我的数据库中没有任何内容。
// This will send the request to the server
samptime = millis();
rpm = (samptime + 333) % 96789;
String request = "10.0.0.244:8000/ardulog/default/add/"+String(samptime)+"/"+String(rpm)+" HTTP/1.1";
Serial.println("\ntrying: ");
Serial.println("GET " + request);
Serial.println("host: minion.local");
client.println("GET " + request);
client.println("host: minion.local");
// if there are incoming bytes available
// from the server, read them and print them:
while (client.available()) {
char c = client.read();
Serial.print(c);
}
Serial.println("closing connection");
client.stop();
我尝试了我能想到的所有变体,但只得到了以下几点:
connecting to minion.local
[hostByName] request IP for: minion.local
[hostByName] Host: minion.local IP: 10.0.0.244
Requesting:
GET 10.0.0.244:8000/ardulog/default/add/112725/16269 HTTP/1.1
host: minion.local
closing connection
wait 5 sec...
为什么我没有读取从服务器返回的任何内容?
发布于 2018-06-29 03:56:27
解决了!尽管我在Google上的POSTing失败了,但只需将单词从GET改为POST就可以在Web2Py上工作,而不会发送任何正文数据:
if(client.connect(host,port))
client.println("POST /ardulog/default/add/" + String(samptime)+ "/" + String(rpm) + " HTTP/1.1");
(仍然没有收到来自服务器的结果页面)
https://stackoverflow.com/questions/51087602
复制相似问题