Hi,
I came so far:
Code: Select all
TgboHTTP = class
private
FHTTP: TScHttpWebRequest;
public
constructor Create;
destructor Destroy; override;
procedure Post(const AURI: string; const AStream, AResultStream: TStream);
end;
procedure TgboHTTP.Post(const AURI: string; const AStream, AResultStream: TStream);
var
AResponse: TScHttpWebResponse;
ABuf: TBytes;
begin
SetLength(ABuf, 0);
AStream.Position:= 0;
AStream.ReadBuffer(ABuf, AStream.Size);
FHTTP.Method := rmPost;
FHTTP.RequestUri:= AURI;
FHTTP.ContentType := 'application/x-www-form-urlencoded';
FHTTP.ContentLength := Length(ABuf);
FHTTP.WriteBuffer(ABuf);
SetLength(ABuf, 0);
AResponse:= FHTTP.GetResponse;
try
AResponse.ReadBuffer(ABuf);
AResultStream.Size:= 0;
AResultStream.Position:= 0;
AResultStream.WriteBuffer(ABuf, Length(ABuf));
finally
AResponse.Free;
end;
end;
But this does not work, because AResponse.ReadBuffer does not accept a TBytes parameter.
I want to read all the data, the remote side sends. So if you cannot give an example, the following questions occur:
1. Can I rely on the value in AResponse.ContentLength or is it a matter of the remote side, if they give the right value in it?
2. If not, do I have to read chunks unless less bytes are read than assumed?
3. How is it implemented in AResponse.ReadAsString? As I cannot see the code, I have no clue.
3. In the docs, ReadBuffer is declared as
Code: Select all
function ReadBuffer(const Buffer: TValueArr; Offset, Count: integer): integer;
Delphi says, it is
Code: Select all
function ReadBuffer(Buffer: PAnsiChar; Offset: Integer; Count: Integer): Integer;
So is TValueArr = PAnsiChar ?
Your help is appreciated.
best regards
Kai