Sending data from ESP32 to a Web service

I am trying to send data via wifi from esp32 to a web service created by me that receives a string of data and saves it in a .txt file.

My webservice works correctly and when I write a string manually it saves it in the file as expected.

In the ESP32 code I am trying to access the webservice following the steps given in the HTTP POTS provided on the web page of the web service.

My code is:

#include <WiFi.h>
#include <ArduinoHttpClient.h>

const char* nome_rede = "iPhone de *******";
const char* password =  "********";
const char* host = "localhost";
const int httpPort = 80;

WiFiServer server(80);

void setup() {

void loop() {

void http() {

  String PostData = "recebida=1234567890"; //string para teste

  WiFiClient client = server.available();

  if (!client.connect(host, httpPort)) {  //conectar a um determinado host
    Serial.println("conecao ao host falhada");

  if (client) {

    if (client.connected()) {
      Serial.println("Connected to client");
      client.println("POST :/WebService.asmx/HelloWorld HTTP/1.1");
      client.println("Host: localhost");
      client.println("Content-Type: application/x-www-form-urlencoded");
      //client.println("User-Agent: Arduino/1.0");
      //client.println("Connection: close");
      client.print("Content-Length: ");

      Serial.println("Client stop");

    else Serial.println("Cliente not conected");
    // close the connection:

  else Serial.println("Cliente not found");


void conectar_rede() {
  WiFi.begin(nome_rede, password);

  while (WiFi.status() != WL_CONNECTED) {
    Serial.print("A conectar á rede");
  Serial.print("IP address do ESP32: ");

With this code I can connect to wifi and to the host but my .txt file does not get the value 1234567890 of the postData variable.

Someone can tell me how I can do this better to try to get it working?

Best regards and Sorry about my english.

const char* host = "localhost";

You clearly do not understand what the name localhost means. Your Arduino is NOT hosting the service you are trying to "POTS" to, so that name is wrong.

      client.println("POST :/WebService.asmx/HelloWorld HTTP/1.1");

Have you EVER seen a path name that contains a colon? You need to perform a colonectomy.

I have no knowledge about HTTP and for this reason I have these kind of errors.

Are you saying that localhost corresponds to the ip address of my pc?

This and the information provided by the web service to make HTTP POST:

POST /WebService.asmx/HelloWorld HTTP/1.1
Host: localhost
Content-Type: application/x-www-form-urlencoded
Content-Length: length


Can you help me configure what to send in HTTP POST request with this information?

Are you saying that localhost corresponds to the ip address of my pc?

No, that is not what I said, and is not true.

When you have a client that wants to make a request to a server RUNNING ON THE SAME MACHINE, you can use the name "localhost" to bypass the need to know the name or IP address of the machine that the server is running on.

Your client and server are NOT running on the same machine, so you can NOT use the name "localhost".