Page 1 of 1

How to change separator in response from http_server

Posted: Thu May 09, 2019 3:21 pm
by filipESP
My problem concerns post_handler(httpd_req_t *req) function in the http_serwer example.
The response which gets back from my phone to ESP eg. looks like this: var1=aaa&var2=bbb
So, how to change the separator '&' in this response?
I was looking for any info in httpd_txrx.c but I didn't find it.

Re: How to change separator in response from http_server

Posted: Fri May 10, 2019 7:52 am
by permal
From your description, it sounds like it is your phone that sends the parameters, not the ESP. The ampersand (&) is the standard separator used in requests, why do you want to change that?

Re: How to change separator in response from http_server

Posted: Fri May 10, 2019 10:47 am
by filipESP
I would like to configure WiFi password which contains '&',
but this char separates variables inside response, so it generates read fail.

Re: How to change separator in response from http_server

Posted: Fri May 10, 2019 11:13 am
by ESP_Sprite
Suggest you read up on the http specs. Queries like the ones you use are urlencoded, so any 'breaking' characters like & are escaped. (&, specifically, gets replaced by %26.)

Re: How to change separator in response from http_server

Posted: Tue May 14, 2019 6:52 am
by filipESP
Ok, but is it possible to get something like eg. var1aaavar2bbb instead var1=aaa&var2=bbb using esp_idf?

Re: How to change separator in response from http_server

Posted: Tue May 14, 2019 8:49 am
by ESP_Sprite
How do you mean 'to get something like' that? Get from where?

Re: How to change separator in response from http_server

Posted: Tue May 14, 2019 2:33 pm
by fly135
filipESP wrote:
Tue May 14, 2019 6:52 am
Ok, but is it possible to get something like eg. var1aaavar2bbb instead var1=aaa&var2=bbb using esp_idf?
I'm guessing you'll need to do that yourself because it's not something anyone else would want. Just search for every = and &, then remove them from the string.

char *src = "var1=aaa&var2=bbb";
char *dst;

dst = src;
while (*src)
{
if ((*src == '=') || (*src == '&'))
{
src++;
continue;
}
*dst++ = *src++
}
*dst = 0;

Re: How to change separator in response from http_server

Posted: Fri Aug 09, 2019 3:37 pm
by rudi ;-)
filipESP wrote:
Tue May 14, 2019 6:52 am
Ok, but is it possible to get something like eg. var1aaavar2bbb instead var1=aaa&var2=bbb using esp_idf?
why you want do these?
how you parse the vars and value what you get?
params & and value = are html standard

Your theme post sounds more
-> "How Set Query String Parameters"
-> "How Send Query String Parameters"
-> "How Get Query String Parameters"
-> "How Parse Query String Parameters"

like @fly135 give u "Http_Server_Response_Send" example, if you want not use the html rule in your usually esp32_http_send routine / send of data from your http_server on esp32
then you must send "custom" response var1Notvar2sovar3goodvar4ideavar5bettervar6usevar7standardvar8query

for standard Parse/Query ect -
there are standard routines for this available
example in other language client side .. :

Code: Select all

var url_string = "http://www.myesp32server.com/user_info.html?var1=1&var2=3&var3=m2-m3-m4-m5"; 
var url = new URL(url_string);
var c = url.searchParams.get("c");
console.log(c);
if you use your own send params routine on esp32
.. then you must write your own "GET Code"on client side too

is possible - yes - but is it usefull -no-
you can do an enc response ( encrypted ) which inert all vars and you have a client side custom html
which can dec (decrypt ) it.. but this is an other theme and exist in esp-idf also.

hope this helps in your code design - but i suggest you to start understand standards,
then change it for your customly use or create it basicly new

not sure in which language you want start/work/do this
perhabs this 27 examples can be a good begin
parse URL's..

also to learn/hear more about programing language inside and outside the universe :mrgreen:
..the listed 27 examples in the link is part of usually knowledge..

:ugeek:

..
sure
best wishes
rudi ;-)