Hi,
I need to replace
TidHTTP.Post(AURL: string; const ASource: TStream; const AResponseContent: TStream);
with SecureBridge. ASource contains the data to be posted, AResponseContent contains the returned data. We need this often to communicate with webservices.
How can this be done? Can you give an example?
Thank you in advance
Kai
TidHTTP.Post - Replacement with SecureBridge
Re: TidHTTP.Post - Replacement with SecureBridge
To work with the data via the HTTP (HTTPS) protocol, you can use the TScHttpWebRequest component: https://devart.com/sbridge/docs/index.h ... equest.htm You can specify settings for secure connection in the TScHttpWebRequest.SSLOptions property.
You can find the samples of using the TScHttpWebRequest component at our forum: viewtopic.php?f=27&t=36270
You can find the samples of using the TScHttpWebRequest component at our forum: viewtopic.php?f=27&t=36270
Re: TidHTTP.Post - Replacement with SecureBridge
Hi,
I came so far:
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
Delphi says, it is
So is TValueArr = PAnsiChar ?
Your help is appreciated.
best regards
Kai
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;
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;
Code: Select all
function ReadBuffer(Buffer: PAnsiChar; Offset: Integer; Count: Integer): Integer;
Your help is appreciated.
best regards
Kai
Re: TidHTTP.Post - Replacement with SecureBridge
Implemention of the ReadAsString method:
You can use this code to implement data fetching using the ReadBuffer method.
Yes, you are right TValueArr = PAnsiChar.
TScHttpWebResponse.ContentLength returns the content length returned by the query.
Code: Select all
function TScHttpWebResponse.ReadAsString: string;
var
Offset, Count: integer;
begin
Offset := 0;
repeat
if Length(FTmpBuf) - Offset < 1024 then
SetLength(FTmpBuf, Length(FTmpBuf) + BUF_SIZE);
Count := InternalRead(TValueArr(FTmpBuf), Offset, Length(FTmpBuf) - Offset);
Inc(Offset, Count);
until Count <= 0;
Result := Encoding.UTF8.GetString(FTmpBuf, 0, Offset);
end;
Yes, you are right TValueArr = PAnsiChar.
TScHttpWebResponse.ContentLength returns the content length returned by the query.