Cant get Simple HTTP client working

geoffw123
Posts: 4
Joined: Mon Nov 30, 2020 1:32 pm

Cant get Simple HTTP client working

Postby geoffw123 » Mon Nov 30, 2020 1:50 pm

Hello

Newbie esp32 user here, making OK progress so far but cant get this simple HTTP client example working.

I am using a neat free PC Utility Open hardware monitor (https://openhardwaremonitor.org/downloads/)).
This App has a built in HTTP Server. I am running it on a remote laptop, I have opened inbound and outbound ports 8085 on the laptop
and I can then see the served webpage on my main pc, including the json data packet request and response. I did this to prove everything was basically OK before I switched to ESP32 as the client

I can connect OK using ESP32 to my ISP and this connects OK to the Server
  1. if (!client.connect(hostIP, 8085))
  2.     Serial.printf("Failed to connect with hardware server %s!\n", hostIP);
  3.   else
  4.     Serial.printf("Connected with hardware server %s!\n", hostIP);   //<-- good this works

I then call a es32 function, thats gets no reply from the remote laptop server

  1.  client.print("GET /data.json HTTP/1.1\r\nHost: 192.168.0.4:8085\r\n");
I have tried a million combinations of the GET message that I send to the server matching the working version to my pc as close as i can. All combinations with various headers of the GET requests I tried get no valid response

I would be most grateful if there is anyone that likes a challenge and can try this, can you get the client to work on an ESP32 ?

It has got me totally stumped, it should work but just refuses to play ball

Thanks Geoff

felmue
Posts: 70
Joined: Mon Nov 16, 2020 2:55 pm

Re: Cant get Simple HTTP client working

Postby felmue » Mon Nov 30, 2020 3:14 pm

Hello @geoffw123

have you tried with two sets of carriage return / linefeeds at the end of the HTTP GET request? e.g.

Code: Select all

client.print("GET /data.json HTTP/1.1\r\nHost: 192.168.0.4:8085\r\n\r\n");
Thanks
Felix

geoffw123
Posts: 4
Joined: Mon Nov 30, 2020 1:32 pm

Re: Cant get Simple HTTP client working

Postby geoffw123 » Mon Nov 30, 2020 4:24 pm

Hello Felix

Thanks Man, I owe you a pint :)

With a little bit more tinkering of the GET request msg that double linefeeds suggestion solved it for me !!

For info the minimum working GET msg is

Code: Select all

client.print("GET /data.json HTTP/1.1\r\nHost: 192.168.0.4:8085\r\n\r\n");
That http GET request msg is far too fussy for my liking, you miss off that 2nd linefeed and you get no sensible error response back. You miss off the first forward slash in front of data.json and it doesnt work. if you put the root of the url in front of the /data.json part it doest work etc etc.

Thanks again for the tip

Who is online

Users browsing this forum: danpf1, pineapple678 and 112 guests