Reputation: 31
I have to send a file to the local server so I use the httpClient
and try to use the post with the host: http://127.0.0.1:5000/show-version
, In the serial monitor, but it doesn't work, again the ESP is in access point mode
void SendVersion (){
client.begin(HOST);
client.addHeader("Content-Type", "text/plain");
int response = client.POST(version);
if(response>0){
String response = client.getString(); //Get the response to the request
Serial.println(response); //Print return code
Serial.println(response); //Print request answer
}else{
Serial.print("Error on sending POST: ");
Serial.println(response);
}
client.end();
}
Upvotes: 0
Views: 926
Reputation: 7044
127.0.0.1
is a special IP address which means "this computer or device". When you use it on the ESP32 it means the ESP32, not the server you're trying to connect to. It's also known as localhost
- again, shorthand for the computer or device the software is running on. It does not identify an external computer.
You need to use the actual IP address of the server you're trying to connect to. How you'll find that depends on the OS the server is running - if you don't know how to do it, use Google to find out.
And of course, if the ESP32 is in AP mode then the server it's trying to talk to needs to be connected to the ESP32's wifi network in order for the ESP32 to be able to talk to it.
Upvotes: 1