ESP8266 responds using HTTP/0.9?

Hey! I was able to get ESP8266 working with Arduino Mega. My configuration has it set up as a server. I can connect to the server on a computer or Android device, however connecting on an iOS device or using the Safari browser on a Mac does not work.

Digging deeper and attempting to send a bare GET request through a bash terminal, I was presented with the following error:

curl: (1) Received HTTP/0.9 when not allowed

From my understanding, the issue is that iOS and Safari want to use HTTP/1.0 to connect to the server, however the server is responding in HTTP/0.9? I don't have that much networking experience and am rather new to ESP8266.

For those interested, here is the code I am running on the Arduino:

#define serialCommunicationSpeed 115200               
#define DEBUG true                                 
#include <Wire.h>
#include <DS3231.h>

DS3231 clock;
RTCDateTime dt;

void setup()

{
  Serial.begin(serialCommunicationSpeed);  
  Serial.println("Serial ok");         
  Serial1.begin(serialCommunicationSpeed);
  clock.begin();     
  clock.setDateTime(__DATE__, __TIME__);
  InitWifiModule();                              
  pinMode(11,OUTPUT);
  Serial.print("Compiled at ");
  Serial.print(__DATE__);
  Serial.println(__TIME__);
  Serial.print("Debug mode is ");
  Serial.println(DEBUG);
  Serial.println("Now entering main loop...");
}

void loop()                                                         
{

  if(Serial1.available())                                           
 {    
    if(Serial1.find("+IPD,"))
    {
     Serial.println("Request Recieved");
     
     dt = clock.getDateTime();
     delay(10);
     
     
 
     int connectionId = Serial1.read()-48;                                                
     
     String webpage = "<html><body><p>ESP8266Server/";
     webpage.concat("Server Clock: ");
     webpage.concat(dt.year);
     webpage.concat("-");
     webpage.concat(dt.month);
     webpage.concat("-");
     webpage.concat(dt.day);
     webpage.concat(" ");
     webpage.concat(dt.hour);
     webpage.concat(":");
     webpage.concat(dt.minute);
     webpage.concat(":");
     webpage.concat(dt.second);
     webpage.concat("</p></body></html>");
     String cipSend = "AT+CIPSEND=";
     cipSend += connectionId;
     cipSend += ",";
     cipSend +=webpage.length();
     cipSend +="\r\n";
     
     String commands = sendData(cipSend,300,DEBUG); 

     
     if(commands.indexOf("beep") > -1){
       tone(11,500,1000);
     }

     sendData(webpage,1000,DEBUG);
     String closeCommand = "AT+CIPCLOSE="; 
     closeCommand+=connectionId; // append connection id
     closeCommand+="\r\n";    
     sendData(closeCommand,3000,DEBUG);

     
    }
  }
}

String sendData(String command, const int timeout, boolean debug)
{
    String response = "";   
    Serial.print("Command: " + command);                                          
    Serial1.print(command);                                         
    long int time = millis();                                      
    while( (time+timeout) > millis())                                 
    {      
      while(Serial1.available())                                      
      {
        char c = Serial1.read();                                     
        response+=c;                                                  
      }  
    }    
    if(debug)                                                        
    {
      Serial.print(response);
    }    
    return response;                                                  
}

void InitWifiModule()
{
  sendData("AT+RST\r\n", 2000, DEBUG);                                                  
  sendData("AT+CWJAP=\"WIFI NAME CENSORED\",\"WIFI PASS CENSORED\"\r\n", 2000, DEBUG);        
  delay (3000);
  sendData("AT+CWMODE=1\r\n", 1500, DEBUG);                                             
  delay (1500);
  sendData("AT+CIFSR\r\n", 1500, DEBUG);                                             
  delay (1500);
  sendData("AT+CIPMUX=1\r\n", 1500, DEBUG);                                             
  delay (1500);
  sendData("AT+CIPSERVER=1,80\r\n", 1500, DEBUG);                                     
  Serial.println("Server initialized, good to go! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");

}

The idea with my program is to provide commands in the url, like this: SERVERIP/command. Because I am simply searching the serial for the command, a POST request will also work. This system works perfectly fine on Google Chrome. I don't want to mess with TCP clients or other ways of communicating with the project if I can help it as I am developing an app for this and sending GET requests to a server is much easier and simpler. The app is made in MIT App Inventor because it's what I know how to use :slight_smile:. I have made a post on their forums as well to see if it's possible to get it to accept HTTP/0.9. Any help is appreciated.

Not familiar with the ESP8266 and its libraries but I have some suspicions.

You are not explicitly sending any HTTP headers, and I doubt the libraries are doing it for you. As HTTP/0.9 is the only HTTP version that does not start its response with a response header block, your browser then is unable (or unwilling) to process it.

Fixing that might be as simple as this:

     String webpage = "HTTP/1.1 200 OK\r\n\r\n";
     webpage.concat("<html><body><p>ESP8266Server/");
     webpage.concat("Server Clock: ");
     webpage.concat(dt.year);
    // ... and leave the rest of your code unchanged

Note that there must be an empty line between the HTTP header and body, that's what the "\r\n\r\n" is for.

This discussion may be helpful if your browser still refuses to eat the request.

That 100% works. Thank you so much!

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