我正在尝试从 Arduino 向Heroku应用程序发出请求。它返回的只是 Heroku 的 404 页面。所以我用 Python 写了一个类似的脚本,它运行良好。
Arduino代码:
char serverName[] = "ruby-coffee-maker.herokuapp.com";
...
if (!client.connected()) {
Serial.println("connecting...");
if (client.connect(serverName, 80)) {
Serial.println("connected");
// Make a HTTP request
client.println("GET / HTTP/1.0");
client.println();
// Wait for response
delay(100);
// If data can be read from te server, print it
while (client.available()) {
char c = client.read();
Serial.print(c);
}
Serial.print("Done");
client.stop();
}
else {
// If you didn't get a connection to the server:
Serial.println("connection failed");
}
}
Python代码:
import httplib
h = httplib.HTTPConnection("ruby-coffee-maker.herokuapp.com")
h.request("GET", "/")
r = h.getresponse()
data = r.read()
print r.status, r.reason, "\"" + data + "\""
h.close()
我该如何解决这个问题?