How to change separator in response from http_server

filipESP
Posts: 71
Joined: Tue Nov 06, 2018 12:42 pm

How to change separator in response from http_server

Postby filipESP » Thu May 09, 2019 3:21 pm

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.

permal
Posts: 384
Joined: Sun May 14, 2017 5:36 pm

Re: How to change separator in response from http_server

Postby permal » Fri May 10, 2019 7:52 am

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?

filipESP
Posts: 71
Joined: Tue Nov 06, 2018 12:42 pm

Re: How to change separator in response from http_server

Postby filipESP » Fri May 10, 2019 10:47 am

I would like to configure WiFi password which contains '&',
but this char separates variables inside response, so it generates read fail.

ESP_Sprite
Posts: 8922
Joined: Thu Nov 26, 2015 4:08 am

Re: How to change separator in response from http_server

Postby ESP_Sprite » Fri May 10, 2019 11:13 am

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.)

filipESP
Posts: 71
Joined: Tue Nov 06, 2018 12:42 pm

Re: How to change separator in response from http_server

Postby filipESP » 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?

ESP_Sprite
Posts: 8922
Joined: Thu Nov 26, 2015 4:08 am

Re: How to change separator in response from http_server

Postby ESP_Sprite » Tue May 14, 2019 8:49 am

How do you mean 'to get something like' that? Get from where?

User avatar
fly135
Posts: 606
Joined: Wed Jan 03, 2018 8:33 pm
Location: Orlando, FL

Re: How to change separator in response from http_server

Postby fly135 » Tue May 14, 2019 2:33 pm

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;

User avatar
rudi ;-)
Posts: 1698
Joined: Fri Nov 13, 2015 3:25 pm

Re: How to change separator in response from http_server

Postby rudi ;-) » Fri Aug 09, 2019 3:37 pm

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 ;-)
-------------------------------------
love it, change it or leave it.
-------------------------------------
問候飛出去的朋友遍全球魯迪

Who is online

Users browsing this forum: Bing [Bot] and 137 guests