Displaying the client.print in serial

I'm trying to send a rest post via https using my ESP8266. I'm using this guide: http://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/client-secure-examples.html

I'm trying to look at what is being posted to the client here:

client.print(String("GET ") + url + " HTTP/1.1\r\n" +
             "Host: " + host + "\r\n" +
             "User-Agent: BuildFailureDetectorESP8266\r\n" +
             "Connection: close\r\n\r\n");

How would I print this to the console? Would I type the following or is there something that can be more easily produced?

serial.println(String("GET ") + url + " HTTP/1.1\r\n" +
             "Host: " + host + "\r\n" +
             "User-Agent: BuildFailureDetectorESP8266\r\n" +
             "Connection: close\r\n\r\n");

You can use a variable to store the data and next print it to both the client and the serial port

char data[150];
...
...

void loop()
{
  strcpy(data, "GET ");
  strcat(data, url);
  strcat(data, " HTTP/1.1\r\n");
  strcat(data, "Host: ");
  strcat(data, host);
  strcat(data, "\r\n");
  strcat(data, "User-Agent: BuildFailureDetectorESP8266\r\n");
  strcat(data, "Connection: close\r\n\r\n";

  client.print(data);
  Serial.print("data = '");
  Serial.print(data);
  Serial.println("'");
}

Disadvantage is that you need to create a buffer; I used 150 bytes which might be overkill or might be to small.

You can also write a function.

void sendWithDebug(char *dataToSend)
{
  client.print(dataToSend);
  Serial.print(dataToSend);
}

As you don't have to send everything in one block, whenever you need it you can do something like

  sendWithDebug("GET ");
  sendWithDebug(url);
  sendWithDebug(" HTTP/1.1\r\n");
  sendWithDebug("Host: ");
  sendWithDebug(host);
  sendWithDebug("\r\n");
  sendWithDebug("User-Agent: BuildFailureDetectorESP8266\r\n");
  sendWithDebug("Connection: close\r\n\r\n");

sterretje

Thankyou for your response. The latter option is a lot cleaner.

I'm trying to send a rest post

A post is done using POST, not GET.

thomascoope:
sterretje

Thankyou for your response. The latter option is a lot cleaner.

and by using the PROGMEM F() macro (if your sendWithDebug() were to support it), you would even save memory