Chat freely about anything...
User avatar
By brasta
#77497 I run web server on ESP-01 to control GPIO (input/output). To show you this Chrome trick I've attached LED to see visually what is surprising me. To turn ON LED we need just enter to this URL: http://192.168.57.164/gpio/0 , to turn off - URL: http://192.168.57.164/gpio/1 that is we can control LED sending HTTP GET requests.

Like you see in my video it’s enough to correct from 0 to 1 and BEFORE pressing Enter on the keyboard LED change his state. Web sniffer on the left shows that after URL edit we have GET request before it submitting. This behavior is on Chrome browser only and I can’t reproduce the same with Chrome and any other website
[youtube]https://www.youtube.com/watch?v=nzXB6Lls5u4[/youtube]
User avatar
By QuickFix
#77524
User avatar
By jankop
#77526 I think what you consider to be a Chrome trick is the wrong reaction of your program to HTTP queries. I estimate this is related to the favicon browser request. Different browsers may behave differently and therefore the error is only reflected on Chrome.
User avatar
By Robert E.
#77537 There are many ways to access a url, they are called verbs or methods. They are used for reading data, changing data, deleting data or simply for asking if a url exists. What your browser does is submitting "GET /gpio/0" or "GET /gpio/1" and as the name says your app should handle this as a request which reads. Your app should never change any state following a GET request. That's what a POST or PUT request ist for.
Chrome sends some request to your app actually before you press Return. Either it's looking whether this URL exists or it tries to fetch the favicon in advance. But you can be sure Chrome will never send a POST or a PUT request on its own.

Actually it's very simple to implement it right:
* "GET /gpio" should return the current state
* "POST /gpio" with a new value or simply "POST /gpio/X" should change the current state. you have to redirect to "/gpio" afterwards to make it fail-proof.

And always remember: never ever change data using a request which reads data (GET). Have a look at https://en.wikipedia.org/wiki/Hypertext ... fe_methods

There are no tricks here :-)