Created
October 17, 2020 05:57
-
-
Save hideack/be81e05dd6fa7846ae57dad19a723189 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <SPI.h> | |
#include <Ethernet.h> | |
byte mac[] = {0x00,0xAA,0xBB,0xCC,0xDE,0x02}; // イーサシールドのMacアドレス記入 | |
char hostname[] = "***.sqale.jp"; // 契約中のレンタルサーバのホスト名 | |
char serverName[256]; | |
char httpHeaderHost[256]; | |
EthernetClient client; | |
void setup() | |
{ | |
sprintf(serverName, "%s", hostname); | |
sprintf(httpHeaderHost, "Host: %s", hostname); | |
Serial.print("Target host:"); | |
Serial.println(hostName); | |
Serial.begin(9600); | |
if (Ethernet.begin(mac) == 0) { | |
Serial.println("Failed to configure Ethernet using DHCP"); | |
for (;;); | |
} | |
Serial.print("My IP address: "); | |
for (byte n=0; n<4; n++) { | |
Serial.print(Ethernet.localIP()[n], DEC); | |
Serial.print("."); | |
} | |
Serial.println(); | |
delay(1000); | |
Serial.println("connecting..."); | |
if (client.connect(serverName, 80)) { | |
Serial.println("connected"); | |
client.println("GET /hoge/foo HTTP/1.1"); | |
client.println("User-Agent: aruduino"); | |
client.println(httpHeaderHost); | |
client.println(); | |
} else { | |
Serial.println("connection failed"); | |
} | |
} | |
void loop() | |
{ | |
if (client.available()) { | |
char c = client.read(); | |
Serial.print(c); | |
} | |
if (!client.connected()) { | |
Serial.println(); | |
Serial.println("disconnecting."); | |
client.stop(); | |
while(1){} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment