Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By T.Krebs
#78532 I am trying to upload information to my appspot created with Google App Engine. I am able to do it when I in my browser type:
http://myname.appspot.com/query?city=Co ... id=ESP8266
But I cannot get it to work on the ESP8266. Here is my code:

Code: Select all    const char* MY_URL = "http://myname.appspot.com";

    void uploadHTTP() {
       // Define the WiFi Client
       WiFiClient client;
       // Set the http Port
       const int httpPort = 80;

       // Make sure we can connect
       if (!client.connect(MY_URL, httpPort)) {
          return;
       }
       else {
          Serial.println("Connected to MY_URL");
       }

       String url = "/query?city=Copenhagen&temp=20&id=ESP8266";

       // Post to appspot
       if (client.connect(MY_URL, httpPort)) {

          // Sent HTTP POST Request
          client.println("POST " + url + " HTTP/1.1");
          Serial.println("POST " + url + " HTTP/1.1");
          client.println("Host: " + String(MY_URL));
          Serial.println("Host: " + String(MY_URL));
          client.println("User-Agent: Arduino/1.0");
          Serial.println("User-Agent: Arduino/1.0");
          client.print("Content-Length: ");
          Serial.print("Content-Length: ");
          client.println(0);
          Serial.println(0);
          client.println("Content-Type: application/x-www-form-urlencoded");
          Serial.println("Content-Type: application/x-www-form-urlencoded");
          client.println("Connection: close");
          Serial.println("Connection: close");
          }
       //Done
       Serial.println("");
       Serial.println("my HTTP done");
       Serial.println("");
    }
User avatar
By EdTheLoon
#79813 You're sending the wrong data through HTTP.

Code: Select all// You don't need to include /query? here, remove it
String url = "/query?city=Copenhagen&temp=20&id=ESP8266";
// Corrected:
String url = "city=Copenhagen&temp=20&id=ESP8266";


When you're sending the data you set 'Content Length' to zero. This is incorrect. It needs to be the length of the url variable you're using. Use url.length(). You also didn't post the actual data after setting all the headers. The Serial.println's are completely unnecessary, remove them. The entire code section for the HTTP POST should look like this:

Code: Select all// Sent HTTP POST Request
          client.println("POST " + url + " HTTP/1.1");
          client.println("Host: " + String(MY_URL));
          client.println("User-Agent: Arduino/1.0");
          client.println("Content-Type: application/x-www-form-urlencoded");
          client.print("Content-Length: ");
          client.println(url.length());
          client.println("Connection: close");
          client.print("\n\n");
          client.print(url);