Generic HTTP not working with hosted webservices?

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
ftrueck
New user
Posts: 2
Joined: 21 Jun 2016, 00:18

Generic HTTP not working with hosted webservices?

#1 Post by ftrueck » 21 Jun 2016, 00:30

I was debugging my problem for quite a few hours and it seems that the current code base is not able to send data to a hosted website (multi hosting environment).
I think this is because of this snippet:

Code: Select all

 String url = "/";
  url += Settings.MQTTpublish;
  url.replace("%sysname%", URLEncode(Settings.Name));
  url.replace("%tskname%", URLEncode(ExtraTaskSettings.TaskDeviceName));
  url.replace("%id%", String(event->idx));
  url.replace("%valname%", URLEncode(ExtraTaskSettings.TaskDeviceValueNames[varIndex]));
  if (longValue)
    url.replace("%value%", String(longValue));
  else
    url.replace("%value%", toString(value, ExtraTaskSettings.TaskDeviceValueDecimals[varIndex]));

  url.toCharArray(log, 80);
  addLog(LOG_LEVEL_DEBUG_MORE, log);

  String hostName = host;
  if (Settings.UseDNS)
    hostName = Settings.ControllerHostName;
    
  // This will send the request to the server
  client.print(String("GET ") + url + " HTTP/1.1\r\n" +
               "Host: " + hostName + "\r\n" +
               "Connection: close\r\n\r\n");
The result will be: GET /xyz?a={a}&b={b}.... HTTP/1.1

A web server hosted in a multi-hosting environment would expect something like this: GET http://host.com/xyz?a={a}&b={b}.... HTTP/1.1
This is because the webserver will have to route the request to the correct web. This is currently not working.

I'd like to fix it on my own, but I have no idea to build the source code by my own, because I have no idea how to setup the code on my build machine. :)

A quick fix would be (as far as I was understanding the code):

Code: Select all

  // This will send the request to the server
  client.print(String("GET ") + hostName + url + " HTTP/1.1\r\n" +
               "Host: " + hostName + "\r\n" +
               "Connection: close\r\n\r\n");
So I see two options here:
- I could fix it in my build environment, but I'd have to know how to build the code base
- Someone of you would get this into your code base and create a release (which will likely be the slower way) :-)

Any help would be appreciated.

Regards,
Florian

didros
New user
Posts: 2
Joined: 16 Jun 2016, 21:51

Re: Generic HTTP not working with hosted webservices?

#2 Post by didros » 23 Jun 2016, 22:27

Florian,
Are you sure about your suggestion? is that defined in the HTTP protocol?
Sure you don't actually have another issue.
The basic: wrong IP address or hostname in "Controller IP", if hostname set "Locate controller" to "Use Hostname" (use DNS).
More advanced: HTTP redirection sent by the host (this is not supported by ESPEasy as far as I can see).
I can give a try to compile for you, so you could at least test, but be aware that I've done it only once in all my life (just started with Wemos). What is your board?
Cheers,
Didier.

kr0815
Normal user
Posts: 136
Joined: 18 Nov 2015, 18:24

Re: Generic HTTP not working with hosted webservices?

#3 Post by kr0815 » 24 Jun 2016, 00:50

Hello Florian,


how yre you loading it up to your ESP ? With Arduino IDE ? Then you just have to modify whatever you want, compile, load it up ?
Or are you using the pre-compiled versions ?

I came across the same problmes as you, and just coded the URL directly in the code, works for me, but it´s not the best solution
I think some servers also need POST instead of GET

Post Reply

Who is online

Users browsing this forum: No registered users and 41 guests