[fpc-pascal] A simple HTTP request with FPC standard units

silvioprog silvioprog at gmail.com
Fri Nov 23 18:00:25 CET 2012


GREAT unit, I love Free Pascal!

Two errors, with:

================
program project1;

{$mode objfpc}{$H+}

uses
  fphttpclient;

var
  S: string;
begin
  with TFPHttpClient.Create(nil) do
    try
      S := Get(ParamStr(1));
    finally
      Free;
    end;
  WriteLn('Got : ', S);
end.
================

I got:

================
C:\Users\silvioprog\Desktop\test>project1.exe
An unhandled exception occurred at $004115F1:
EHTTPClient: Invalid protocol : ""
  $004115F1
  $0041189E
  $004118FE
  $0040167F  main,  line 13 of project1.lpr
================

With:

================
program project1;

{$mode objfpc}{$H+}

uses
  fphttpclient;

var
  S: string;
begin
  with TFPHttpClient.Create(nil) do
    try
      S := Get('http://silvioprog.com.br');
    finally
      Free;
    end;
  WriteLn('Got : ', S);
end.
================

I got:

================
C:\Users\silvioprog\Desktop\test>project1.exe
An unhandled exception occurred at $0040FE72:
EAccessViolation: Access violation
  $0040FE72
  $00410042
  $00411576
  $004117CE
  $0041182E
  $0040166D  main,  line 13 of project1.lpr
================

What I'm is wrong?

My environment:

Lazarus 1.1 r38836 FPC 2.7.1 i386-win32-win32/win64

2012/11/23 Michael Van Canneyt <michael at freepascal.org>

>
>
> On Fri, 23 Nov 2012, luciano de souza wrote:
>
>  Hello listers,
>> Using Synapse, the developer has very good features to deal with the
>> HTTP protocol. But imagine you want only to do a "get" in a URL and
>> take a string back. I imagine it can be done with the standard units
>> of Freepascal. Is it true? How could I do it with FPC 2.7.1?
>>
>
> very simple:
>
> uses fphttpclient;
>
> Var
>   S : String;
>
> begin
>   With TFPHttpClient.Create(Nil) do
>     try
>       S:=Get(ParamStr(1));
>   finally
>     Free;
>   end;
>   Writeln('Got : ',S);
> end.
>
> home: >fpc -S2 th.pp
> /usr/bin/ld: warning: link.res contains output sections; did you forget -T?
> home: >th http://www.freepascal.org/
> Got : <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
> <html>
> <!-- Web Page Design by James Koster - http://www.jameskoster.co.uk  and
> Marko Mihel?i? - http://www.mcville.net-->
>
> <head>
>
> I cut off the rest.
>
> Michael.

-- 
Silvio Clécio
My public projects - github.com/silvioprog
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20121123/da9e840d/attachment.html>


More information about the fpc-pascal mailing list