Click here to Skip to main content
15,895,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to use http.begin() method in HTTPClient Library to program esp32 cam. i have an api that uses for sendein sms that works fine in http.begin(myApiAddress) and also i can use myApiAddress in an address bar a browser like google chrome or any browser and i have same result that is good . but when i want to use my Local_IP_Addrsss like(192.168.1.84:8089) in http.begin(Local_IP_Addrsss); i have result under detai : Error on HTTP request. while to trying to use Local_IP_Addrsss in an address bar a browser it works fine . so how can i use Local_IP_Addrsss in http.begin (); like is using as well in a Address bar of a browser. Any help can be helpful.

What I have tried:

i used http.addHeader("Content-Type", "text/html");
after http.begin(Local_IP_Addrsss ) But was ineffective.
Posted
Updated 14-May-21 20:35pm
v3
Comments
Richard MacCutchan 15-May-21 6:00am    
You need to show more of your code, and the exact error message, and show where it occurs. Also what class is the http instance created from?
Member 13128846 15-May-21 6:23am    
#include <wifi.h>
#include <httpclient.h>

const char* ssid = "My-SSID";
const char* password = "My-Password";

IPAddress ip;
IPAddress local_IP(192, 168, 1, 88);
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 0, 0);
IPAddress primaryDNS(8, 8, 8, 8); //optional
IPAddress secondaryDNS(8, 8, 4, 4); //optional

void setup() {

Serial.begin(115200);
HTTPClient http;
Serial.println("Try Connecting to ");
Serial.println(ssid);

if (!WiFi.config(local_IP, gateway, subnet, primaryDNS, secondaryDNS))
{
Serial.println("STA Failed to configure");
}

Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {
delay(1000);
}
Serial.println("");
Serial.println("WiFi connected successfully");
Serial.print("Got IP: ");
ip = WiFi.localIP();
Serial.println(ip); //Show ESP32 IP on serial

Serial.println("HTTP server started");
delay(100);

http.begin("http://ip.sms.ir/SendMessage.ashx?user=[user]&pass=[pass]&text=[text]&to=[to]&lineNo=[lineNo]"); //works fine also works fine in a browser.
http.begin("http://192.168.1.88:8081"); //Not Working Here
(but in a browser http://192.168.1.88:8081 works fine)

int httpCode = http.GET();

if (httpCode > 0)
{
String payload = http.getString();
Serial.println(httpCode);
Serial.println(payload);
}

else
{
Serial.println("Error on HTTP request");
}

http.end(); //Free the resources

}
void loop() {

}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900