I have a google cloud run function that I need to connect to using my ESP32 so that I can obtain a token. But unfortunately, it always gives me connection refused error. I have added the google root certificate and I have the correct payload I need because I have verified that the cloud run function is actually working because the curl function actually returns the payload. And when I try using the esp32, I cannot even see the refused logs in the cloud run logs which leads me to believe it is something related to the connection between the google cloud and the esp32 itself.
HTTPClient http;
http.setTimeout(30000);
//the client successfully begins
if (!http.begin(client, "xxx.a.run.app"))
{
Serial.println("Failed to initialize HTTPClient for JWT POST");
client.stop();
return;
}
else
{
.println("HTTPClient initialized for JWT POST");
}
payload = xxxx
int httpCode = http.POST(payload);
if (httpCode > 0)
{
Serial.printf("HTTP POST returned: %d\n", httpCode);
String response = http.getString();
Serial.println("Response: " + response);
}
else
{
Serial.printf("HTTP POST failed: %s\n", http.errorToString(httpCode).c_str());
//this is where i get the error saying 'connection refused'
}
http.end();
client.stop();
Below is the serial monitor output
HTTPClient initialized for JWT POST
Payload to send: {"jwt":"xxx"}
HTTP POST failed: connection refused
What could be the reason for the refusal of connection?
I have tried to get the result by using curl and I also have used the roots.pem (all the certificates not just the root certificate) to connect to the google cloud and it actually works meaning that I believe the cloud run function is working as expected. I want to get the response back from the google cloud run function using esp32 and I would like to know why is this error is being caused? Thanks!
clientis instantiated.