EldoS | Feel safer!

Software components for data protection, secure storage and transfer

TElHTTPSClient.Post - XML File encoding

Also by EldoS: CallbackProcess
A component to control process creation and termination in Windows and .NET applications.
#30205
Posted: 08/05/2014 06:11:48
by Dennis Ratzek (Standard support level)
Joined: 07/28/2014
Posts: 9

Hello,

I am using Delphi XE2 and the version 12.0.257

when i try to send a XML file with the TElHTTPSClient the Server tells me that the XML File i provided is not valid. But it is valid.

i was confused, because the size of the file did match. so i tried to reconvert the MemoryStream in the TElHTTPSClient.Post(URL: string;content: string) function.

Code
SetString(p, PAnsiChar(S.Memory), S.Size);


That is the original Content:
<?xml version="1.0" encoding="iso-8859-1"?>
<xreq:XMLTransport..
...
<xcpt:Manufacturer>Stollfuß</xcpt:Manufacturer>
..
</xreq:XMLTransport>

when i convert the stream back the last closing '>' is missing because the 'ß' now has 2 characters.

<?xml version="1.0" encoding="iso-8859-1"?>
<xreq:XMLTransport..
...
<xcpt:Manufacturer>Stollfuß</xcpt:Manufacturer>
..
</xreq:XMLTransport

The Encoding is mentioned in the XML file. Can you help me with this Problem? Do i have to manually convert it and use the TElHTTPSClient.Post(URL: string;content: ByteArray) Function?
#30206
Posted: 08/05/2014 06:23:50
by Vsevolod Ievgiienko (EldoS Corp.)

Thank you for contacting us.

TElHTTPSClient sends data as-is without any conversions, so method that accepts a stream should work. Could you please post your code here that puts XML content into a stream.
#30207
Posted: 08/05/2014 06:32:52
by Dennis Ratzek (Standard support level)
Joined: 07/28/2014
Posts: 9

I don't, i pass the XML file as a string. In SecureBlackbox Version 9 it did work.

Code
Function TSendData.sendWithDigestAuth(aURL, aData, aUri: String): integer;
Var
  durchgang: integer;
Begin
  FDigestAuthentification_step := 2;

  FHttpsClient.SSLEnabled := True;
  FHttpsClient.ClientCertStorage := Nil;
  FUseDigestAuthentification := True;

  FHttpsClient.RequestParameters.Authorization := getDigestAuthString(aUri);
  FIsBusy := True;

  Result := FHttpsClient.Post(aURL, aData);
  FHttpsClient.Close;




This is the function in FHttpsClient.Post which converts the XML file(string) into the Memory stream i guess.
Code
Tmp := StrToUTF8(Content);
S.Write(Tmp[0], Length(Content));
#30208
Posted: 08/05/2014 07:19:48
by Vsevolod Ievgiienko (EldoS Corp.)

The problem is somehow related to the String data type and conversion of Unicode to binary. What you can try to do is to replace StrToUTF8 with our BytesOfString method and check if this helps.
#30209
Posted: 08/05/2014 08:23:54
by Dennis Ratzek (Standard support level)
Joined: 07/28/2014
Posts: 9

Thank you, the BytesOfString method works. Do you plan to adjust something or do i have to keep a local copy of the SBHTTPSClient.pas in my Project folder to avoid this Problem?

Is this maybe a Problem with the compiling? I am using Delphi XE2 and installed the 'SecBBox16.groupproj' package. The BytesOfString method is the else case in the TElHTTPSClient.Post() method.

Code
  {$ifndef SB_ANSI_VCL}
  Tmp := StrToUTF8(Content);
   {$else}
  Tmp := BytesOfString(Content);
   {$endif}



EDIT: i didn't think straight. i just use
Code
Result := FHttpsClient.Post(aURL, BytesOfString(aData));

that should solve my Problem. Sorry for my last post ;-)
#30210
Posted: 08/05/2014 08:35:38
by Vsevolod Ievgiienko (EldoS Corp.)

You can convert a string to ByteArray using BytesOfString manually and then pass it to another Post method overload that accepts ByteArray instead of string and doesn't perform internal conversion.
Also by EldoS: CallbackProcess
A component to control process creation and termination in Windows and .NET applications.

Reply

Statistics

Topic viewed 735 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!