[fpc-pascal] set useragent in fphttpclient?

waldo kitty wkitty42 at windstream.net
Mon Oct 15 22:09:33 CEST 2012


how do i set the useragent field in a client built with fphttpclient?

i'm starting with the example "httpget" and then moving on from there...

i've tried various WAGs like

RequestHeaders(fieldUserAgent,'my user agent');
RequestHeaders('User-Agent','my user agent');
SetRequestHeaders(fieldUserAgent,'my user agent');
SetRequestHeaders('User-Agent','my user agent');

but i can't find the combination :/

do they need to be set before the "With TFPHTTPClient.Create(nil) do" line??


===== code =====
program Project1;

{$mode objfpc}{$H+}

uses
   {$IFDEF UNIX}{$IFDEF UseCThreads}
   cthreads,
   {$ENDIF}{$ENDIF}
   Classes,
   { you can add units after this }
   SysUtils, fphttpclient;

var
   i : Integer;

begin
   if (ParamCount<>2) then
     begin
     writeln('Usage : ',ExtractFileName(ParamStr(0)), ' URL filename');
     Halt(1);
     end;
   With TFPHTTPClient.Create(Nil) do
     try
       RequestHeaders('User-Agent','Mozilla/5.0 (compatible; fpweb)');
       Get(ParamStr(1),ParamStr(2));
       Writeln('Response headers:');
       For I:=0 to ResponseHeaders.Count-1 do
         Writeln(ResponseHeaders[i]);
     finally
       Free;
     end;
end.
===== end code =====



More information about the fpc-pascal mailing list