I don’t have the transceiver so i want to use WIFI. So what i have done is to create a host and connect to my localhost using WIFI, however using localhost does not work as part of the paths, so i use IP.
The actual page is set at http://localhost:54062/api/Environment/Save, so i use 192.168.1.100:54062/api/env/save. How do i connect using Wifi?
I have this
const char* host = "192.168.1.80"; WiFiClient client; const int httpPort = 54062; if (!client.connect(host, httpPort)) { Serial.println("connection failed"); return;
this works gets me connected to IP but not to “save” part
This does not work http://localhost:54062/api/Environment/Save
nor http://192.168.0.80:54062/api/Environment/Save
Thanks
Hello, unfortunately I’m not sure I understand exactly what you’re trying to do…
- Do you want your ESP to make an HTTP request to another device on that URL?
- Or do you want to turn your ESP in a web server to receive requests on that URL?
Which project are you following from my courses? Thanks!
i want to connect to my localhost, which is connecting to a Web API on my PC. it has a URL http://192.168.0.80:54062/api/Environment/Save, const char* host = http://192.168.0.80:54062/api/Environment/Save does not work
So this is what i want to connect to http://localhost:54062/api/Environment/Save , i substitute the localhost for physical IP address.. but not working
Based on that information, it looks like you’re doing everything right. If the ESP8266 is connected to the same network and your web api, you can connect to it using the IP address, port and define the path URL /api/Environment/Save. So, I’m not sure what’s missing…
sure, but how do you define the URL and send that?
const char* host = “192.168.1.80”; which is localhost
In reality i wanted host to be http://localhost:54062/api/Environment/Save like in postman
// Use WiFiClient class to create TCP connections
WiFiClient client;
const int httpPort = 54062;
if (!client.connect(host, httpPort)) {
Serial.println(“connection failed”);
return;
Now where do i include the the rest of the URL /api/Environment/Save
I guess many of us use localhost.. You must know postman? it post and sends data to localhost.
Yes, I’m familiar with Postman for HTTP quests and API testing. You can only use localhost when you’re making requests to your web app with the same computer (because it has the same IP address).
When the ESP32 calls a service to your laptop, you need to use the IP address of the device that is connecting to (instead of the localhost).
Yes, defining the IP address like that is how you do it.
const char* host = "192.168.1.80";
Regards,
Rui
the full path is http://localhost:54062/api/Environment/Save
Localhoost = “192.168.1.80” Port is 54062
what about the rest? How do i get to this /api/Environment/Save
In the section that you do the POST or GET, you can enter the path of the request. As follows:
client.println(“POST /api/Environment/Save TTP/1.1”);
client.println(“Host: “192.168.1.80);
Why is that?
I think that if you set the port and the host (the other device IP address or domain name), you just need to add the path to the request like I’ve mentioned in my previous comment…
It always worked for me like that…