Question: Can the ESP-IDF acquire integers from a HTTP URI?
Background: I am currently working on a program in C that replicates some endpoints used by a Raspberry Pi (Python). An example of a Pi URI is something like "/grab/4", where it is registered as "/grab/<int:amount>" in the code and amount can be used no problem. To my understanding, where a request is sent to the ESP, it is only capable of obtaining variables from the header or queries, not as parsable variables in the URI. I'd like to know If anyone has any experience with this or can provide some reasons to why this might be.
HTTP Server URI Question
-
- Posts: 9724
- Joined: Thu Nov 26, 2015 4:08 am
Re: HTTP Server URI Question
Depends on the http server you're using. If using esp-httpd (the one included in esp-idf), you could simply register your own get (or post) handler for the "/grab/*" url and parse the url yourself.
Re: HTTP Server URI Question
How would you obtain whatever argument is input for *?ESP_Sprite wrote: ↑Thu Oct 28, 2021 12:53 amDepends on the http server you're using. If using esp-httpd (the one included in esp-idf), you could simply register your own get (or post) handler for the "/grab/*" url and parse the url yourself.
-
- Posts: 9724
- Joined: Thu Nov 26, 2015 4:08 am
Re: HTTP Server URI Question
It's essentially a string, so standard C functions will work: sscanf, atoi, strstr etc. You'd use a combination of those.
Re: HTTP Server URI Question
Hello!
I'm facing the same problem with the httpd example provided by the esp idf, but i cant find a Method to grab the acutal URL. I found no function, or structure in which the URL ist stored.
You might have some ideas, on how to obtain the URL?
I'm facing the same problem with the httpd example provided by the esp idf, but i cant find a Method to grab the acutal URL. I found no function, or structure in which the URL ist stored.
You might have some ideas, on how to obtain the URL?
Re: HTTP Server URI Question
Looks like if you input the string "grab/*" for the .uri when making the http_uri_t variable, the * gets registered as a string, so only get/* can be called, not get/whatever.ESP_Sprite wrote: ↑Fri Oct 29, 2021 5:29 amIt's essentially a string, so standard C functions will work: sscanf, atoi, strstr etc. You'd use a combination of those.
-
- Posts: 9724
- Joined: Thu Nov 26, 2015 4:08 am
Re: HTTP Server URI Question
Was wondering about your response because I actually have it working in a bunch of my apps... Turns out it's a configuration option. You need to set 'config.uri_match_fn = httpd_uri_match_wildcard;' in the httpd_config_d struct when you initialize esp_httpd to make wildcards work; the default is a strcmp() that indeed would have the behaviour you describe.
Re: HTTP Server URI Question
Ahhhh, thank you. I am currently using HTTPD_SSL_CONFIG_DEFAULT() for the HTTPS server and had no idea what a wildcard was. I will play around with it and see how it goes.ESP_Sprite wrote: ↑Sat Oct 30, 2021 2:06 amWas wondering about your response because I actually have it working in a bunch of my apps... Turns out it's a configuration option. You need to set 'config.uri_match_fn = httpd_uri_match_wildcard;' in the httpd_config_d struct when you initialize esp_httpd to make wildcards work; the default is a strcmp() that indeed would have the behaviour you describe.
Re: HTTP Server URI Question
Sorry for the late response, I had to prioritize a different project. The solution works great! I appreciate the help.
Who is online
Users browsing this forum: Bing [Bot], Majestic-12 [Bot] and 166 guests