-->
Page 1 of 1

HTTP Client Post Request.

PostPosted: Sun Feb 24, 2019 7:25 pm
by ESPCrypt
Hello,

I would like to enquire about the syntax in regards to a POST request and sending a variable within that request.

The below for example will successfully POST a request of 2 specific values.

int httpcode = http.POST("uservalue=112233&user=7");

However what I would like to achieve is sending a String/Variable as one of the values. Something like this -

int httpcode = http.POST("uservalue=(VARIABLEHERE)&user=7");

Is this possible?

Thank you.

Re: HTTP Client Post Request.

PostPosted: Tue Feb 26, 2019 4:27 am
by QuickFix
Not really an ESP topic, but with strings you should URL-encode parameters. :idea:

Re: HTTP Client Post Request.

PostPosted: Tue Feb 26, 2019 7:28 am
by Bonzo
If you build up the string outside the post it will work but I have not tried it the way you want.

Out of interest have you actually tried it?

Code: Select allString data = "uservalue=" + VARIABLEHERE + "&user=7";

int httpcode = http.POST(data);


I think this correct except there might be a problem with variable types.

Re: HTTP Client Post Request.

PostPosted: Tue Feb 26, 2019 10:03 am
by martinayotte
Bonzo wrote:
Code: Select allString data = "uservalue=" + VARIABLEHERE + "&user=7";


I think this correct except there might be a problem with variable types.


It should be the following instead :

Code: Select allString data = String("uservalue=") + VARIABLEHERE + "&user=7";