jstrausd / ESP8266AsyncHttpClient

AsyncHttpClient Library for ESP8266 (GET and POST Requests)
MIT License
12 stars 3 forks source link

Output of GET request of url says: connect failed #2

Closed Marc1200 closed 1 year ago

Marc1200 commented 1 year ago

Hello,

I use this piece of code, but when i execute this i get connect failed error. aClient.init("GET","http://server.com/push.phpfirstname=Jonathan&lastname=Strauss"); aClient.send()

I use this link to do a get request: http://api.callmebot.com/text.php?user=@username&text=This+is+a+test+from+CallMeBot

Whats the problem?

Molock33 commented 1 year ago

Hi. Perhaps a "/" and a "?" between push.php and firstname ?

Marc1200 commented 1 year ago

I will try, but that is the example link which will certainly not work, but i use the http://api.callmebot.com/text.php?user=@username&text=This+is+a+test+from+CallMeBot

I can try to insert a slash between text.php? And user

Molock33 commented 1 year ago

No sorry, the night was very short, sorry ^^' Just a "?", no need a "/" ....

? is just for separate the filename from the first parameter, other are separate bt "&"

Marc1200 commented 1 year ago

Okay then the url was right, but i got the error from this function: Screenshot_20221123-104751-320

Is this because my url is a CNAME record and not a A record?

Molock33 commented 1 year ago

Are you sure your url is correct ? You wrote: [quote]I use this piece of code, but when i execute this i get connect failed error. aClient.init("GET","http://server.com/push.phpfirstname=Jonathan&lastname=Strauss"); aClient.send()[/quote]

Between push.php and firstname there's no sign of "?"

Marc1200 commented 1 year ago

No sorry i would say with that, that i use that example code with my api.callmebot url

Molock33 commented 1 year ago

Could you post more code ?

Marc1200 commented 1 year ago

image image

The code is part of a esphome project. The ESP8266 act as a AsyncTCPserver, it receives messages from an alarmsystem. in the yaml file i look for the received message and send a message to a phone with the AsyncHTTPclient

jstrausd commented 1 year ago

I updated the Library, please try it again with the newest version. Also i tried it by myself with the URL "http://api.callmebot.com/text.php?user=marc2143&text=Alarm" and it worked.

Code:

aClient.setDebug(true);
aClient.init("GET","http://api.callmebot.com/text.php?user=marc2143&text=Alarm");
aClient.send();

Log:

IP address: 10.0.0.31
Type: GET URL: http://api.callmebot.com/text.php?user=marc2143&text=Alarm DataMode:  Data: 
[AsyncHttpClient] Connected

Response: 536
HTTP/1.1 200 OK
Date: Sun, 27 Nov 2022 18:09:59 GMT
Server: Apache/2.4.29 (Ubuntu)
Cache-Control: no-cache
Vary: Accept-Encoding
Transfer-Encoding: chunked
Content-Type: text/html; charset=UTF-8

1e8
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-149177385-1"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag("js", new Date());

  gtag("config", "UA-149177385-1");
</script>
<font face=
Response: 168
"Courier New,Digital, Arial, Helvetica, sans-serif">User: marc2143<br>Text: Alarm<br>HTML format: no<br>Preview Links: no<br><br>Name: Marc<br>Status: Successful
0

[AsyncHttpClient] Disconnected

If the error still occurs, check if it is an general Internet/Wifi (DNS or like that) problem? Or try a other URL and check if this works, like google.com or something.

Marc1200 commented 1 year ago

Hello,

thanks for updating te library, it was indeed a wifi problem, i added wifi connection valus to the tcpasync8266 file now the url is working. now i have one problem more, when i do a http get request with 2 url's it won't work. Do you have a function in de library by which i can check when the http client disconnected?

the configuration is now: httpasync.init("GET","telegram url"); httpasync.send(); httpasync.init("GET","whatsapp url "); httpasync.send();