Recent

Author Topic: [SOLVED] TFPHTTPClient FormPost different behaviour depending on argument type  (Read 468 times)

apeoperaio

  • Full Member
  • ***
  • Posts: 170
Dear all,
I noticed that TFPHTTPClient.FormPost acts differently if I call:
Code: Pascal  [Select]
  1. FormPost(const URL: string; FormData: TStrings;
  2.   const Response: TStream);
or
Code: Pascal  [Select]
  1. FormPost(const URL, FormData: string;
  2.   const Response: TStream);  

If I pass FormData as TStrings the FormPost procedure performs EncodeURLElement that is not performed if I pass FormData as simple string to FormPost.

There are no difference in the behaviour if the data in FormData does not need to be encoded, but it has difference behaviour for strings including not allowed characters (e.g., '@', '='...).

I didn't find the TFPHTTPClient documentation so I do not know if it is a feature or a bug.

Opinions?

I am using FPC 3.0.4
« Last Edit: January 20, 2020, 02:43:59 pm by apeoperaio »

lainz

  • Hero Member
  • *****
  • Posts: 3472
    • Lainz
Re: TFPHTTPClient FormPost different behaviour depending on argument type
« Reply #1 on: January 20, 2020, 02:02:38 pm »
It's a feature.

A string is not that easy (but possible) to urlencode, since it must split it all elements, where in a TStrings or TStringList there are key=value pairs, finding a key it gets the value, and it just encodes the value.

Encoding the entire url with keys and values produces an invalid url.

apeoperaio

  • Full Member
  • ***
  • Posts: 170
Re: TFPHTTPClient FormPost different behaviour depending on argument type
« Reply #2 on: January 20, 2020, 02:43:42 pm »
Ok, thank you!