Lazarus

Programming => Networking and Web Programming => Topic started by: berghem on March 01, 2021, 08:54:41 pm

Title: [RESOLVEDfphttpclient
Post by: berghem on March 01, 2021, 08:54:41 pm
I had copy this code for send a json in a server web, https://wiki.freepascal.org/fphttpclient#Posting_JSON

but when compiled I have this error
"unit1.pas(44,27) Error: Identifier not found "TRawByteStringStream""

but this class uses Classes and I have in my uses....

where is the problem?
I use Lazarus 2.0.6


Code: [Select]
var
    Client: TFPHttpClient;
    Response : TStringStream;
    Params : string = '{"title": "Some New Note","content": "This is awesome stuff in the new note"}';
begin
    Client := TFPHttpClient.Create(nil);
    Client.AddHeader('User-Agent','Mozilla/5.0 (compatible; fpweb)');
    Client.AddHeader('Content-Type','application/json; charset=UTF-8');
    Client.AddHeader('Accept', 'application/json');
    Client.AllowRedirect := true;
    //Client.UserName:=USER;
    //Client.Password:=PW;
    client.RequestBody := TRawByteStringStream.Create(Params);
    Response := TStringStream.Create('');
    try
        try
            client.Post('TheURL', Response);
            writeln('Response Code is ' + inttostr(Client.ResponseStatusCode));   // better be 200
        except on E:Exception do
                writeln('Something bad happened : ' + E.Message);
        end;
    finally
        Client.RequestBody.Free;
        Client.Free;
        Response.Free;
    end;
Title: Re: fphttpclient
Post by: dseligo on March 02, 2021, 08:20:25 am
I tried your code and it compiles (I use Lazarus 2.0.10).
Check if you have TRawByteStringStream declaration in "lazarus\fpc\3.2.0\source\rtl\objpas\classes\classesh.inc" (change 3.2.0 according to FPC version you have).
Title: Re: fphttpclient
Post by: Leledumbo on March 02, 2021, 09:08:51 am
TRawByteStringStream was implemented on 2020-01-03.
Quote
r43845 | ondrej | 2020-01-03 03:02:27 +0700 (Jum, 03 Jan 2020) | 1 line

classes: introduce TRawByteStringStream
Lazarus 2.0.6 comes with FPC 3.0.4 which was released on 2017-11-28.
Title: Re: fphttpclient
Post by: PascalDragon on March 02, 2021, 09:13:44 am
TRawByteStringStream requires 3.2.0 or newer. You might be able to simply use TStringStream instead.
Title: Re: fphttpclient
Post by: berghem on March 02, 2021, 09:14:28 pm
Resolved with StringStream.

Thanks
TinyPortal © 2005-2018