0
我環顧四周,找不到任何類似我想要做的事情。如何使用WiFly從Arduino Uno R3做GET請求?
背景:我試圖從這個API調用http://api.football-data.org這個API的足球信息通過WiFly盾牌進入我的Arduino。現在這裏有一些我想出來的代碼來獲取這些信息。但是,這段代碼還沒有工作。
#include <SPI.h>
#include "WiFly.h" //include the WiFly experimental library
char server[] = "api.football-data.org";
WiFlyClient client(server, 80);
void setup(){
Serial.begin(9600);
Serial.println("Serial Begun :D");
WiFly.begin();
Serial.println("WiFly Begun :D");
Serial.print("IP: ");
Serial.println(WiFly.ip()); //print out WiFly IP
}
void loop(){
if(client){
while(client.connected()){
if(client.available()){
char c = client.read();
delay(10);
Serial.print(c);
if(c == '\n'){
Serial.println("connected");
client.print("GET http://api.football-data.org/alpha/soccerseasons/357/leagueTable");
Serial.print("GET http://api.football-data.org/alpha/soccerseasons/357/leagueTable");
client.println(" HTTP/1.1");
Serial.println(" HTTP/1.1");
client.println("Host: api.football-data.org");
Serial.println("Host: api.football-data.org");
client.println("X-Auth-Token: (My Token here)");
Serial.println("X-Auth-Token: (My Token here)");
client.println("Connection: close");
Serial.println("Connection: close");
client.println();
}
}
}
delay(100);
client.flush();
client.stop();
}
}
我應該做些什麼改變才能從api.football-data.org服務器獲得正確的HTTP響應?