Recent

Author Topic: [RESOLVEDfphttpclient  (Read 631 times)

berghem

  • Jr. Member
  • **
  • Posts: 53
[RESOLVEDfphttpclient
« 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;
« Last Edit: March 02, 2021, 09:37:57 pm by berghem »

dseligo

  • Full Member
  • ***
  • Posts: 156
Re: fphttpclient
« Reply #1 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).

Leledumbo

  • Hero Member
  • *****
  • Posts: 8319
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: fphttpclient
« Reply #2 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.

PascalDragon

  • Hero Member
  • *****
  • Posts: 2895
  • Compiler Developer
Re: fphttpclient
« Reply #3 on: March 02, 2021, 09:13:44 am »
TRawByteStringStream requires 3.2.0 or newer. You might be able to simply use TStringStream instead.

berghem

  • Jr. Member
  • **
  • Posts: 53
Re: fphttpclient
« Reply #4 on: March 02, 2021, 09:14:28 pm »
Resolved with StringStream.

Thanks

 

TinyPortal © 2005-2018