On Mon, 15 Oct 2012, waldo kitty wrote:


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');

Try
  AddHeader('User-Agent','My user agent');

as in

   With TFPHTTPClient.Create(Nil) do
    try
      AddHeader('User-Agent','Mozilla/5.0 (compatible; fpweb)');
      Get(ParamStr(1),ParamStr(2));
      Writeln('Response headers:');


Michael.



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>  With TFPHTTPClient.Create(Nil) do
   try
     RequestHeaders('User-Agent','Mozilla/5.0 (compatible; fpweb)');
     Get(ParamStr(1),ParamStr(2));
     Writeln('Response headers:');
 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 =====
_______________________________________________
fpc-pascal maillist  -  [email protected]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

_______________________________________________
fpc-pascal maillist  -  [email protected]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to