spaces in url request

#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>

const char* ssid = "xxxxx";
const char* password = "xxxx";
const char* host = "script.google.com";
const int httpsPort = 443;
WiFiClientSecure client;
 

void setup() {
  Serial.begin(115200);
  while (!Serial);

  Serial.print("\n\nConnecting to WiFi ...");
  WiFi.begin(ssid, password);
 
}

void loop() {
//  if(Serial.available()) {
//      String theTime = Serial.readString();
//      Serial.print(theTime);
      sendDate();
      delay(10000);

}


void sendDate(){
  
      
//      int strLen = request.length() + 1;
//
//      char char_array[strLen];
//
//      request.toCharArray(char_array, strLen);
//      const char* theRequest = request.c_str();
//      
//      
//      Serial.println(theRequest);
      
     

    String testing = "testing_this";
    String requestOne = "GET /macros/s/xxxxxxxxxxxxxxxxxx/exec?addData=";
    String http = " HTTP/1.1";

    String request = requestOne + testing+ http;
    
    
      if( WiFi.status()== WL_CONNECTED ){
         while (WiFi.status() != WL_CONNECTED) delay(100);
  Serial.println("...Connected");

  client.setInsecure();
  if (!client.connect(host, httpsPort)) {
    Serial.println("connection failed");
    return;
  }

  client.println(request);
  client.print("Host: "); client.println(host);
  client.println("User-Agent: ESP8266");
  client.println("Connection: close\r\n");

  Serial.println("request sent");

  while (client.connected()) {
    while (client.available()) Serial.write(client.read());
  }
  client.stop();
      }
}

that string where it says testing is the string im trying to send how if i put it how it is now “testing_this” with the underscore as a space it works fine but lets say i did “testing this” with a space it wont send is there anyway i can send it with a space?

I think that I remember using %20 for space in HTML. See here.

%20 worked thank you

Space is not the only character that is a problem. If you want to learn more, search for "URL encoding".

For the Arduino, you could start looking here:

To be really really sure, you'd replace everything EXCEPT alpha-numerics with percent encodings.

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