我正在尝试使用以太网盾的Arduino来调用PHP脚本。域名如下:sub.domain.com
我要调用的脚本就像这样script.php?value1=value&somevalue2=somevalue&value3=somevalue
。
我尝试使用Arduino库附带的示例,但我没有成功。
EthernetClient ethClient;
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xEF };
char server[] = "sub.domain.com";
void setup() {
[...]
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
}
[...]
}
void loop() {
[...]
if (ethClient.connect(server, 80)) {
Serial.println("Conected to: " + String(server));
String getUrl = "/script.php?location=" + String(LOCATIONID) + "&sc=2&feedP=" + String(feedBar) + "&returnP=" + String(returnBar) ;
Serial.println(getUrl);
// Make a HTTP request:
ethClient.println("GET " + getUrl + " HTTP/1.1");
ethClient.println("Host: sub.domain.com");
ethClient.println("Connection: close");
ethClient.println();
} else {
// if you didn't get a connection to the server:
Serial.println("Could not connect to: " + String(server));
}
if (ethClient.available()) {
char c = ethClient.read();
Serial.println("Respons: ");
Serial.print(c);
}
[...]
}
答案 0 :(得分:-1)
不使用子域时可以正常工作。