Go Down

Topic: Using the Arduino Ethernet to connect to a website (Read 902 times) previous topic - next topic


Hi everyone, I've been busy making my Arduino Ethernet connect to my website and I finally made it work. So I giving you the working code in the hope that it will help out those in the need. I added my trials and notes within.

Code: [Select]

#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { The mac adress of your Arduino };
//char server[] = "http://www.abc.com"; // Nothing happens
//char server[] = "www.abc.com"; // OK
//char server[] = "abc.com"; // OK
byte server[] = { ip of abc }; // OK

EthernetClient client;

void setup()

 if (Ethernet.begin(mac) == 0) {
   Serial.println("Failed to configure Ethernet using DHCP");

 Serial.print("My IP address: ");

 if (client.connect(server, 80)) {
   client.println("GET /arduino.php?q=data HTTP/1.0");
   client.println("Host: abc.com"); // OK -> It solves the Arduino sending the query to abc.com instead of abc.com IP.
   //client.println("Host: www.abc.com"); // OK
   //client.println("User-Agent: arduino-ethernet"); // This doe'nt work.  You can get 403 - Forbidden using this
   client.println("User-Agent: Mozilla/5.0"); // OK -> This solve the 403 - Forbidden problem
   client.println("Connection: close");
 else {
   Serial.println("connection failed");

void loop()
 if (client.available()) {
   char c = client.read();

 if (!client.connected()) {

Enjoy this Arduino script.

Go Up