Open TCP connection oddities

RollingRocker
Posts: 16
Joined: Tue Feb 09, 2021 10:45 pm

Open TCP connection oddities

Postby RollingRocker » Thu Feb 11, 2021 3:27 am

When setting up the ESP32 to fetch a web page, I use this command:

AT+CIPSTART="TCP","www.mydomainnamegoeshere.com",80
Started.
Requesting URL.
AT+CIPSEND=13
GET /a1.txt


it does successfully open the connection to the website.

HOWEVER: in reality it is opening a connection to the TCP address of that domain name AND NOT to the actual website itself.

For example:
say www.mydomainnamegoeshere.com resolves to 9.9.11.11
and on that Windows IIS web server I have 100 websites and 1 "default" site that only responds to the IP address itself and no domain name.

default site: responds to 9.9.11.11
all other 100 sites: respond to their unique domain name which is at 9.9.11.11 but when a web browser client requests those pages, it passes along the domain name in the request and the request is routed to the appropriate website.
then that site responds and sends back the data.

this is exactly what is going on for me.

my site is running on 9.9.11.11 but since the ESP32 is not "passing along" the domain name in the actual HTTP request, it's fetching the file from the default (IP ONLY) unused server instance instead of the site that is running the actual domain name itself.

I am SURE some of you have experienced this already. Is there any way for me to make the ESP HTTP requests properly pass along the domain name so that web servers can route the request to the appropriate domain?

markkuk
Posts: 38
Joined: Wed Mar 27, 2019 11:50 am

Re: Open TCP connection oddities

Postby markkuk » Thu Feb 11, 2021 11:55 am

You need to include the Host: header in your HTTP request:

Code: Select all

GET /a1.txt HTTP/1.1
Host: www.mydomainnamegoeshere.com
See: https://developer.mozilla.org/en-US/doc ... nt_request

Alternatively, you could use a HTTP connection instead of a plain TCP connection:
https://docs.espressif.com/projects/esp ... mands.html

Who is online

Users browsing this forum: No registered users and 99 guests