W5500 as client requesting from localhost leads to "404 301 File not found Error"

Hi guys,

I have a W5500 running as a client. When I start the scetch the W5500 connects to my localhost (xampp Apache Server), but the server reports a "HTTP/1.1 404 Not Found" and "The requested URL was not found on this server". So the client can communicate to the server and the server is answering.

The files like index.php etc. are stored at the apache document root folder. Calling the index.php from my web browser works fine. But as I sayed when the W5500 sends a request it fails.

Reading the Apache access.log I saw that besides a 404 error there is also a 301 error (redirect). google told me that 301 error can come from https problem and I think the W5500 does not support https. Maybe this is a problem.

I'm absolutely new to Ethernet, Apache, XAMPP, Webdevelopment etc. Searching the Internet didn't help me to fix the problem, so I really need your help here.

Some Infos:

The Scetch

/*
  Web client

 This sketch connects to a website (http://www.google.com)
 using an Arduino Wiznet Ethernet shield.

 Circuit:
 * Ethernet shield attached to pins 10, 11, 12, 13

 created 18 Dec 2009
 by David A. Mellis
 modified 9 Apr 2012
 by Tom Igoe, based on work by Adrian McEwen

 */

#include <SPI.h>
#include <Ethernet2.h>

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// if you don't want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server:
IPAddress server(192, 168, 178, 21);

// Set the static IP address to use if the DHCP fails to assign
IPAddress ip(192, 168, 178, 20);

// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);

  // start the Ethernet connection:
  Serial.println("Starting");
  
    Ethernet.begin(mac, ip);
  // give the Ethernet shield a second to initialize:
  delay(1000);
  Serial.println("connecting...");

  // if you get a connection, report back via serial:
  if (client.connect(server, 80)) {
    Serial.println("connected");
    // Make a HTTP request:
    client.println("GET /index.php&cmd=cmd_shsreport HTTP/1.1"); //  /search?q=arduino HTTP/1.1
    client.print("Host: ");
    client.println(server);
    client.println("Connection: close");
    client.println();
  }
  else {
    // kf you didn't get a connection to the server:
    Serial.println("connection failed");
  }
}

void loop()
{
  // if there are incoming bytes available
  // from the server, read them and print them:
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }

  // if the server's disconnected, stop the client:
  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();

    // do nothing forevermore:
    while (true);
  }
}

The serial output

The Apache access.log

192.168.178.20 - - [18/Mar/2022:09:01:32 +0100] "GET /index.php&cmd=cmd_shsreport HTTP/1.1" 404 301 "-" "-"

If you need more information just let me know.

Regards,
Siblette.

Wild guessing because I haven't seen your server config: you ask the wrong virtual host. As you specify the IP address:

as the hostname you probably end in the fallback host of the Apache. Replace "server" by the actual hostname you used in the Apache config.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.