Forum > Networking and Web Programming

TFPHTTPClient debugging

<< < (2/6) > >>

Gustavo 'Gus' Carreno:
Hey SymbolicFrank,

AHHH, sorry, I completely forgot that you can also hook up on these events to have access to what's happening during the actual method call:

https://gitlab.com/freepascal.org/fpc/source/-/blob/main/packages/fcl-web/src/base/fphttpclient.pp#L373

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---  TFPHTTPClient = Class(TFPCustomHTTPClient)  Published    {Shortened to make a point}    Property OnRedirect;    Property OnPassword;    Property OnDataReceived;    Property OnDataSent;    Property OnHeaders;    Property OnGetSocketHandler;
Cheers,
Gus

Thaddy:
Indeed TFPCustomHTTPClient exposes more (inheritance) and even more from what TFPCustomHTTPClient inherits.
Follow the breadcrumps.

SymbolicFrank:

--- Quote from: Thaddy on May 23, 2022, 07:04:08 pm ---200 is not the only legal response code. 301 and 302 are too (redirections, there are more...like for old security protocols) and quite very common nowadays.
https://en.wikipedia.org/wiki/HTTP_301
https://en.wikipedia.org/wiki/HTTP_302

So if you expect 200 rightaway you are making a programmer error.
Simply set AllowRedirects to true. Eventually you should get 200.

--- End quote ---
Yes, and you can turn redirecting on. But it is the TFPHTTPClient that only allows 200 and raises an exception on everything else. try..except won't help, because the response isn't read at all. So if you get a 400+, you cannot see what the error was.

SymbolicFrank:

--- Quote from: Gustavo 'Gus' Carreno on May 23, 2022, 08:00:46 pm ---Hey SymbolicFrank,


--- Quote from: SymbolicFrank on May 20, 2022, 04:23:03 pm ---Also, seeing what message (and headers!) is actually sent is quite hard.

--- End quote ---

If you look at the code (https://gitlab.com/freepascal.org/fpc/source/-/blob/main/packages/fcl-web/src/base/fphttpclient.pp#L373) you can see that TFPHTTPClient exposes these, among many:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---  TFPHTTPClient = Class(TFPCustomHTTPClient)  Published    { Shortened to make a point }    Property RequestHeaders;    Property RequestBody;    Property ResponseHeaders;    Property ResponseStatusCode;    Property ResponseStatusText;    Property Cookies;    Property Proxy;  end;
If you're looking to inspect the Request Headers before you perform a method, that would be RequestHeaders.
If you're looking to inspect the Request Body, usually empty if you don't place anything there, that would be RequestBody.
If you want to inspect the Response Headers after you've performed a method, that would be ResponseHeaders.

Cheers,
Gus

--- End quote ---

Yes, but there are a lot of rules they have to conform to for them to be added to the message. So you have to override multiple methods to be able to see what is sent just before it is. That is the problem.  Ok, you can check the ResponseHeaders, unless you got something else than a 200.

SymbolicFrank:

--- Quote from: Gustavo 'Gus' Carreno on May 23, 2022, 08:05:35 pm ---Hey SymbolicFrank,


--- Quote from: SymbolicFrank on May 23, 2022, 03:09:33 pm ---How do you add parameters?
--- End quote ---

If you're looking for a way to add parameters like one is used to on Postman, or some other HTTP Client object implementations you will not find any.

It's up to you to add the question mark symbol and the name, value pairs in the URL string that you pass to any method call.
Same with the anchor side of things: it's up to you to put the hash symbol and the name of the anchor if you want to have that in.

But I do agree that it would be a good Quality of Life type of feature that could be added without much effort.

Cheers,
Gus

--- End quote ---

Yes, and I did.

The TFPHTTP client expects a server, a path and a file to get. For most modern sites the URL is a function to call and a set of parameters. 20 years ago that would have been totally fine. Today, not so much.

And I did add and fix it all. This is just my feedback on what definitely could (and probably should) be improved.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version