EldoS | Feel safer!

Software components for data protection, secure storage and transfer

HTTPCLient with NG edition

Also by EldoS: CallbackDisk
Create virtual disks backed by memory or custom location, expose disk images as disks and more.
#30676
Posted: 09/11/2014 01:42:33
by Walter Schrabmair (Priority Standard support level)
Joined: 05/03/2013
Posts: 150

I have Porblems in XE6 with the NG edition to receive text from the site.
In MMLOG.Text there are strange characters in it.
I have tried this routine at ondata.

Code
procedure TForm1.ElHttpsClient1Data(Sender: TObject; Buffer: Pointer;
  Size: Integer);
var
//S : {$ifndef Unicode}string{$else}AnsiString{$endif};
S : AnsiString;
merged,arr1, arr2: Ansistring;
begin
  SetLength(S, Size);
  Move(Buffer^, S[1], Size);
  elHttpsClient1.OutputStream := nil; // MyStream3;
  // MMLog.Text := MMLog.Text + S;  // compiler error!
  MMLog.Text := MMLog.Text + ConvertoString(S);   //MMLOG.Text is grap
  //ANsiBuffer := ANsiBuffer + s;
  // I also tried that following merging, but Ansistring merged has also grap.
  SetLength(merged, Length(ansibuffer) + Size);
  if ansibuffer <> nil then Move(ansibuffer[0], merged[0], Length(ansibuffer));
  if S <> nil then Move(S[0], merged[Length(ansibuffer)], Length(S));
  AnsiBuffer:= merged;
  Application.ProcessMessages;
end;

with that also converting routine.
Code
function TForm1.ConverToString(var MyByteArray: ByteArray): String;
var
   Unicodestr: string;
begin
SetString(UnicodeStr, PWideChar(@MyByteArray[0]), Length(MyByteArray) div 2);  
Result:=Unicodestr;
end;

Here I have no compiler error anymore, but the TMEMO is still strange characters! I have XE6 with NG Edition for ANdroid.
Code
procedure TForm1.ElHttpsClient1Data(Sender: TObject; Buffer: Pointer;
  Size: Integer);
var
//S : {$ifndef SB_Unicode_VCL}string{$else}AnsiString{$endif};
S : AnsiString;
merged,arr1, arr2: Ansistring;
begin
  SetLength(S, Size);
  Move(Buffer^, S[1], Size);
  elHttpsClient1.OutputStream := nil; // MyStream3;
  MMLog.Text := MMLog.Text + string(S);
  Application.ProcessMessages;
end;
#30677
Posted: 09/11/2014 01:48:18
by Vsevolod Ievgiienko (EldoS Corp.)

Hello.

Please try to convert incoming data to string using our StringOfBytes or UTF8ToStr functions.
#30680
Posted: 09/11/2014 04:26:49
by Walter Schrabmair (Priority Standard support level)
Joined: 05/03/2013
Posts: 150

If I use StringOfBytes then I get Length(MMLOG.Text) = 0!
Nothing

Must I define SB_UNICODE_VCL? even for NG?

the buffer (S variable) begins with #0 !
So the converting makes a empty string.
#30681
Posted: 09/11/2014 04:36:43
by Vsevolod Ievgiienko (EldoS Corp.)

Please check Size value in the debugger. Does the client receive anything from the server? If yes then there is a bug in you code that is reponsible for conversion of incoming data to text.
#30682
Posted: 09/11/2014 04:46:44
by Walter Schrabmair (Priority Standard support level)
Joined: 05/03/2013
Posts: 150

Size(S) = 403 after converting string is empty.
I think ther is a bug in your code.
Try yourself. Make a get to:

http://www.lipometer.com/uploads/media/chemikreg.php?Username=MyUser&Local_ip=1

my OnData routine is:
Code
procedure TForm1.ElHttpsClient1Data(Sender: TObject; Buffer: Pointer;
  Size: Integer);
var
//S : {$ifndef SB_Unicode_VCL}string{$else}AnsiString{$endif};
S : AnsiString;
begin
  SetLength(S, Size);
  Move(Buffer^, S[1], Size);
  elHttpsClient1.OutputStream := nil; // MyStream3;
  MMLog.Text := MMLog.Text + UTF8ToSTring(S);
  showMessage(' size(S): '+inttostr(size)+'String: '+UTF8ToString(S));
  Application.ProcessMessages;
end;


Must I define any directive in my UNIT ?
#30683
Posted: 09/11/2014 04:49:37
by Vsevolod Ievgiienko (EldoS Corp.)

Try this code:

Code
procedure TForm1.ElHttpsClient1Data(Sender: TObject; Buffer: Pointer;
  Size: Integer);
var
  S : ByteArray;
begin
  SetLength(S, Size);
  Move(Buffer^, S[0], Size);
  MMLog.Text := MMLog.Text + StringOfBytes(S); // or UTF8ToStr(S)
  Application.ProcessMessages;
end;
#30684
Posted: 09/11/2014 05:01:53
by Walter Schrabmair (Priority Standard support level)
Joined: 05/03/2013
Posts: 150

Great! It works!
Thanks a lot!
Walter
#30687
Posted: 09/11/2014 07:27:43
by Walter Schrabmair (Priority Standard support level)
Joined: 05/03/2013
Posts: 150

Just to let you know that with UTF8ToStr only the first 57 bytes are stored in TMEMO. YOu must use StringOfBytes to work properly.
Also by EldoS: CallbackFilter
A component to monitor and control disk activity, track file and directory operations (create, read, write, rename etc.), alter file data, encrypt files, create virtual files.

Reply

Statistics

Topic viewed 496 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!