* * *

Author Topic: [SOLVED] Error in most basic TFPHTTPClient usage  (Read 4908 times)

Dimitrios Chr. Ioannidis

  • New member
  • *
  • Posts: 41
    • Nephelae
Re: [solved] Re: Error in most basic TFPHTTPClient usage
« Reply #15 on: July 08, 2016, 02:16:31 am »
So it seems reasonable to expect fcl-web to pass a default agent header.

( Quoting  Remy Lebeau )

"The User-Agent header is optional in RFC 2616. It SHOULD be used by clients, but it is not REQUIRED to be used. All of the major third-party browsers/clients use it, but custom apps/APIs/bots/etc might not. There are webservers that alter responses, or even reject requests (which is annoying), based on the User-Agent provided (or lack of one)."

PLz, fill a feature request ... ( IMO it's not a bug ).

regards,
Dimitrios Chr. Ioannidis
http://www.nephelae.eu

BBasile

  • Sr. Member
  • ****
  • Posts: 358
Re: [solved] Re: Error in most basic TFPHTTPClient usage
« Reply #16 on: July 08, 2016, 02:23:28 am »
Thx much for reading the doc for me.

It's an API. Shouldn't at least had a quick look how to use it ?  ;) :D

( Couldn't believe that fphttpclient failed in such basic operation .... )

I've made the typical error that people do with tech docs and manuals. They read only the section that they interested by and miss a lot of things...

BBasile

  • Sr. Member
  • ****
  • Posts: 358
Re: [solved] Re: Error in most basic TFPHTTPClient usage
« Reply #17 on: July 08, 2016, 06:53:29 pm »
( Couldn't believe that fphttpclient failed in such basic operation .... )

Yes, BBasile should probably file a bug report. Looking at Synapse, it appears it use "Mozilla/4.0 (compatible; Synapse)" as default agent. And Indy appears to use "Mozilla/3.0 (compatible; Indy Library)". So it seems reasonable to expect fcl-web to pass a default agent header.

I assume Apple's NSMutableURLRequest class does that, perhaps identifying itself as Safari, since I didn't need to set any headers for it to work correctly.

-Phil

http://bugs.freepascal.org/view.php?id=30359

Already closed.

Phil

  • Hero Member
  • *****
  • Posts: 2380
Re: [solved] Re: Error in most basic TFPHTTPClient usage
« Reply #18 on: July 08, 2016, 07:15:33 pm »
http://bugs.freepascal.org/view.php?id=30359

Already closed.

Hmm, my source for Synapse does this in THTTPSend.Create:

  FUserAgent := 'Mozilla/4.0 (compatible; Synapse)';

Hence why I said that Synapse "appears" to set the user agent.

Not sure if I understand Michael's comment.

-Phil

ChrisR

  • New member
  • *
  • Posts: 37
Re: [SOLVED] Error in most basic TFPHTTPClient usage
« Reply #19 on: December 20, 2017, 02:35:14 pm »
I realize this is an old thread. However, the function below takes extends the example from Dimitrios Chr. Ioannidis to report the latest github release

Code: Pascal  [Select]
  1. function latestGitRelease(url: string): string;
  2. //Returns string for latest release (error will return empty string)
  3. //example
  4. // latestGitRelease('https://api.github.com/repos/rordenlab/dcm2niix/releases/latest');
  5. //will return
  6. // "v1.0.20171204"
  7. const
  8.      key = '"tag_name":"';
  9. var
  10.   s, e: integer;
  11.   cli: TFPHTTPClient;
  12. begin
  13.   result := '';
  14.   cli := TFPHTTPClient.Create(nil);
  15.   cli.AddHeader('User-Agent','Mozilla/5.0 (compatible; fpweb)');
  16.   try
  17.     try
  18.       result := Cli.Get(url);
  19.     except
  20.       result := '';
  21.     end;
  22.   finally
  23.     cli.free
  24.   end;
  25.   if length(result) < 1 then exit;
  26.   s := posex(key, result);
  27.   if s < 1 then begin
  28.      result := '';
  29.      exit;
  30.   end;
  31.   s := s+length(key);
  32.   e:= posex('"', result, s);
  33.   if e < 1 then begin
  34.      result := '';
  35.      exit;
  36.   end;
  37.   result := copy(result, s, e-s);
  38. end;  
 

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus