Access Point - Extract query from URL

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
skywest
Posts: 2
Joined: Sat Feb 20, 2021 8:45 pm

Access Point - Extract query from URL

Post by skywest » Sat Feb 20, 2021 8:55 pm

Hi,

Complete MicroPython newbie here.

I have set up an ESP8266 as access point and defined a simple web page served to any browser connecting to it.
If the browser connects to the access point with a query string attached to the url, e.g 192.168.4.1?var1=10&var2=20 ..... etc., what method would the ESP8266 use to extract these values from the url?

Any pointers appreciated!

User avatar
jimmo
Posts: 2236
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: Access Point - Extract query from URL

Post by jimmo » Fri Feb 26, 2021 1:21 am

skywest wrote:
Sat Feb 20, 2021 8:55 pm
If the browser connects to the access point with a query string attached to the url, e.g 192.168.4.1?var1=10&var2=20 ..... etc., what method would the ESP8266 use to extract these values from the url?
Can you provide more information about how your web server works?

When the browser connects to http://hostname/foo/bar?a=b it will say

GET /foo/bar?a=b HTTP/1.1
Host: hostname

So you can extract the url parameters from the GET line. In Python the easiest way to do this (if your web server library doesn't already do this for you) is using split.

Post Reply