TScHttpWebResponse / accented characters

Discussion of open issues, suggestions and bugs regarding network security and data protection solution - SecureBridge
Post Reply
turck
Posts: 2
Joined: Wed 28 Jul 2021 20:36

TScHttpWebResponse / accented characters

Post by turck » Wed 04 Aug 2021 08:37

Hello
I am using Delphi 7 and SecureBridge V9.5 - Standard

When I open the URL directly in Firefox I get a correct XML file

<?xml version="1.0" encoding="ISO-8859-1"?>
<liste>
<libelle>Chpt France par équipes féminin</libelle>
</liste>

The wording is in French with 2 accented characters (char 233)

In Delphi I cannot find these 2 characters which are replaced by "?"

<? xml version = "1.0" encoding = "ISO-8859-1"?>
<list>
<libelle>Chpt France par ?quipes f?minin</libelle>
</list>

I have tried several encodings but nothing helps.

Code: Select all

  url := 'https://apiv2.fftt.com/mobile/pxml/xml_epreuve.php?organisme=1&type=E&......';

  ScHttpWebRequest1: = TScHttpWebRequest.Create (url);
  try
    Response: = ScHttpWebRequest1.GetResponse;
    ResponseStr: = (Response.ReadAsString);
    if IsXMLWellFormed (ResponseStr) then
    begin
      XMLDocument1.Active: = false;
      XMLDocument1.XML.Text: = ResponseStr;
      XMLDocument1.Active: = true;
      XMLDocument1.SaveToFile ('Atexte.xml');
      XMLDocument1.Active: = false;
    end;
  finally
    ScHttpWebRequest1.Free;
  end;
Remarks :
response.ContentEncoding is empty
response.Headers.ToString ends with
- content-type: application / xml
- charset: ISO-8859-1

Can you help me find a solution to this problem?
Thank you

automatic translation with translate.google
Last edited by turck on Sat 07 Aug 2021 09:25, edited 1 time in total.

YanishevskiyVI
Devart Team
Posts: 70
Joined: Wed 02 Jun 2021 09:30

Re: TScHttpWebResponse / accented characters

Post by YanishevskiyVI » Fri 06 Aug 2021 10:48

Hi there,

Method ScHttpWebRequest1.GetResponse.ReadAsString expects response to have a UTF-8 encoding, and decodes them as UTF-8.

You may get response content "as-is" by using

- ScHttpWebRequest1.GetResponse.ReadAsBytes

- ScHttpWebRequest1.GetResponse.ReadToStream

You may apply encoding as follow:

Code: Select all

uses ...CLRClasses 
... 
var 
  Buf: TBytes; 
  Str: string; 
... 
  buf := ScHttpWebRequest1.GetResponse.ReadAsBytes; 
  Str := Encoding.GetEncoding(28591).GetString(Buf, 0, Length(Buf)); 
... 
Where 28591 is an ISO 8859-1 CodePage identifier as described here:
https://docs.microsoft.com/en-us/window ... dentifiers

Regards,
Vitaliy

turck
Posts: 2
Joined: Wed 28 Jul 2021 20:36

Re: TScHttpWebResponse / accented characters

Post by turck » Sat 07 Aug 2021 09:26

it's perfect, thank you very much for your help

YanishevskiyVI
Devart Team
Posts: 70
Joined: Wed 02 Jun 2021 09:30

Re: TScHttpWebResponse / accented characters

Post by YanishevskiyVI » Mon 09 Aug 2021 12:29

I'm glad to hear that your issue is resolved. Free free to contact us anytime in case you get any other questions.

Regards,
Vitaliy

Post Reply