PHP -> JSON ->Zlib -> Delphi XE7 [win32 -> work | android -> No mapping ] [Edit] #2

Мy program for android should get data from the server as json when to perform under Win32 works, and in android error, please help!

PHP:
{code}
$err = array();
$data = array('id'=>1,'name'=>'test','info'=>'1234');
$inf = array('data' => $data ,'error' => $err);
$json = json_encode($inf);
$json = gzencode(trim(preg_replace('/\s+/',' ',$json )),9);
header('Content-Encoding: gzip');
header("content-type: text/html; charset: UTF-8");
header("cache-control: must-revalidate");
header("expires: ".gmdate("D, d M Y H:i:s",time()+60)." GMT" );
header('Content-Length: ' . strlen( $json ) );
header('Vary: Accept-Encoding');
echo $json;
{code} 

Delphi XE7:

{code}
uses ..., IdCompressorZLib;

var
  LoginInfo: TStringList;
  Response: TStringStream;
  data string;
  http: TIdHTTP;
  cook: TIdSSLIOHandlerSocketOpenSSL;


    http:= TIdHTTP.Create();
    http.ConnectTimeout:= 30000;
    http.Compressor:= TIdCompressorZLib.Create();
    cook:= TIdSSLIOHandlerSocketOpenSSL.Create();
    http.IOHandler:= cook;

    LoginInfo := TStringList.Create;
    Response := TStringStream.Create('');
    LoginInfo.Add('cmd=get');
    http.Post('https://site/api/get.php',LoginInfo,Response);
    http.Disconnect;
    data:= Response.DataString;
    Memo1.Lines.Add(data);
{code}

For win32 work good!
If run to Android show error: *"No mapping for the Unicode character exists in the target multi-byte code page"*, mpirically established that an error occurs in *data:= Response.DataString;*

If transfer data without compression is working well in android :(

P.S
The same problem found on the _http://stackoverflow.com/questions/24652341/no-mapping-for-the-unicode-character-exists-in-the-target-multi-byte-code-page/29664299#29664299_ and the author said that to work, but I do not work, grateful for the help!

Edited by: Andri Diuk on Apr 16, 2015 4:15 AM
0
Andri
4/16/2015 11:16:17 AM
embarcadero.delphi.firemonkey 4901 articles. 4 followers. Follow

2 Replies
1350 Views

Similar Articles

[PageSpeed] 16

Andri wrote:

> header("content-type: text/html; charset: UTF-8");

You are sending JSON data, but telling the client that you are sending HTML 
instead.  You are also not using the correct sytax for specifying a charset. 
 Use this instead:

{code}
header("content-type: application/json; charset=UTF-8");
{code}

Or this:

{code}
header('content-type: application/json; charset="UTF-8"');
{code}

And then, of course make sure the JSON data you are compressing is actually 
UTF-8 encoded.

> Response := TStringStream.Create('');

When using TStringStream in D2009+, if you do not specify an encoding in 
the constructor, TEncoding.Default will be used.  On Windows, TEncoding.Default 
maps to TEncoding.Ansi.  On POSIX system (which includes Android), TEncoding.Default 
maps to TEncoding.UTF8.  So make sure you are specify the correct charset 
that the server is actually using, eg:

{code}
Response := TStringStream.Create('', TEncoding.UTF8);
{code}

A better option would be to not use TStringStream at all.  Use TMemoryStream 
instead and then decode it manually based on the TIdHTTP.Response.Charset 
property after TIdHTTP.Post() exits:

{code}
Response := TMemoryStream.Create;
http.Post('https://site/api/get.php',LoginInfo,Response);
Response.Position := 0;
data := ReadStringAsCharset(Response, http.Response.Charset);
{code}

A better option is not use a response TStream at all.  Since JSON is textual 
data, TIdHTTP can charset-decode it automatically for you:

{code}
data := http.Post('https://site/api/get.php',LoginInfo);
{code}

> For win32 work good!
> If run to Android show error: *"No mapping for the Unicode character exists
> in the target multi-byte code page"*, mpirically established that an error
> occurs in *data:= Response.DataString;*

You did not specify an encoding in the TStringStream constructor, so TEncoding.Default 
gets used.  If the uncompressed JSON bytes contain non-ASCII characters using 
byte sequences that do not match the Default encoding, the decode will fail.

The fact that TEncoding.Default is ANSI on Windows and the decode works, 
and that TEncoding.Default is UTF-8 on Android and the decode fails, suggests 
that your server is NOT actually UTF-8 encoding the JSON correctly.

> If transfer data without compression is working well in android :(

That suggests the compression itself may be malforming the JSON data.

> The same problem found on the
> _http://stackoverflow.com/questions/24652341/no-mapping-for-the-unicod
> e-character-exists-in-the-target-multi-byte-code-page/29664299#2966429
> 9_

That is a link to your own answer, which was deleted 1 hour after you posted 
it.  In any case, I already posted an answer of my own to that question yesterday. 
 

-- 
Remy Lebeau (TeamB)
0
Remy
4/16/2015 5:17:57 PM
> {quote:title=Remy Lebeau (TeamB) wrote:}{quote}

Very, very grateful, I found experimentally that it is necessary to use Response := TStringStream.Create('',TEncoding.UTF8); and was resolved to check my question on the forum, I was impressed, use your extra cultivate, it worked!

Edited by: Andri Diuk on Apr 16, 2015 2:27 PM
0
Andri
4/16/2015 9:27:48 PM
Reply:

Similar Artilces:

Does Delphi XE5 on Android work with the Android emulator? [Edit]
I find that even a hello-world app exactly like the one that David I outlines (add a button, one line of code, set button text) will not run on the Android Emulator configured out of the box. First, after installing the Rad Studio XE5 trial, I followed David I's steps exactly, and the emulator would not even start. Then I clicked Android SDK manager, updated it, and clicked run-without-debugging. It asked me if I wanted to start the emulator this time so I did. Now the Firemonkey app will not start up the emulator, and while it does appear to start debugging, the emulator scree...

Is dll developed in Delphi 6 works on Delphi 2?
I have a one dll, whose work is to creates a form with some normal vcl controls, print selected tables and email some reports. It was developed in Delphi 6. Can any other application which was developed in Delphi 2 use that dll.? If not, please let me know in which areas i need change. The dll work is only to print and email. With regards, Srikanth Varma Srikanth varma wrote: > I have a one dll, whose work is to creates a form with some normal > vcl controls, print selected tables and email some reports. It was > developed in Delphi 6. Can any other application which was d...

Code works in Delphi 7 but not in Delphi 2010 [Edit]
hello, i have a procedure that open's a file by passing the file name as the parameter to the executable. something like this {code} C : \ P r o g r a m F i l e s \ Da c k e r \ D r a c k e r . e x e " G : \ D E l p h i 7 \ D e l p h i 7 A p p _ l o g . t " {code} The source code is {code} procedure OpenFileWithExe var hReg: HKEY; Ret: Longint; RegDataType, RegDataSize: DWORD; CmdLine: array [0..560] of Char; Len: Integer; SInfo: TStartupInfo; PInfo: TProcessInformation; begin Ret := windows.RegOpenKeyEx(HKEY_CURRENT_USER, ...

FastScript in Delphi XE8
*Edit: This is now solved, but I leave the original message below for reference. The solution was essentially to delete all traces of FastReports (That's "Reports", not "Script") from the computer, as it was interfering with FastScript. This was actually fairly involved to do, and we did it under the supervision of someone from FastScript tech support, who was extremely helpful. If you run into the problem described below, be sure to contact their technical support and see if maybe you are experiencin g the same issue, and how to resolve it. I hope this is helpfu...

FireDAC / Delphi XE7 / Firebird 2.5 + Dialect 3: Key fields turn upper case [Edit] #2
Hi, When working wih a SQL dialect 3 database and field names in upper/lower case, I used to reference those fields in double quotes on my old Delphi 2010 with IBX, which worked well enough. After migrating to XE7 with the latest FireDAC, I set IndexFieldNames to "Mmm" including the double quotes. "Mmm" is also my only primary key field. When opening the table, FireDAC executes an SQL statement that ends with {code}ORDER BY A."Mmm" ASC, A.MMM ASC{code} which of course delivers an exception because there is no field MMM. I hope it is ok if I post some singl...

Is there Delphi implementation (For Older Delphi also) of zlib 1.2.4
Hello, Does anyone have zlib 1.2.4 version of Delphi, with new Objects, maybe pZLibEx (http://www.dellapasqua.com/delphizlib/) port with compiled Objects? -TP- > {quote:title=Tommi Prami wrote:}{quote} > Hello, > > Does anyone have zlib 1.2.4 version of Delphi, with new Objects, maybe > pZLibEx (http://www.dellapasqua.com/delphizlib/) port with compiled Objects? > > -TP- \zlib-1.2.4\contrib\delphi\zlib.pas On 4.4.2010 13:43, Ralf Stocker wrote: >> {quote:title=Tommi Prami wrote:}{quote} >> Hello, >> >> Does anyone have zl...

Delphi for PHP or Delphi PRISM
Hi, I have the opportunity to develop a web-based library management system. Nothing fancy, just being able to do the usual CRUD stuff for books and provide a search facility. Borrowing is to be done via an email request to the library admin who then sends out the book(s). Since both Delphi for PHP and Delphi PRISM will enable me to develop the app, which one will allow me to deliver it in less time and also increase (even how small) my marketability as a web developer? Thanks. Phillip Flores Phillip Flores wrote: > Hi, > > I have the opportunity to develop a...

SEPA components for Delphi with Source Code (Delphi 5
Hi all, in the european union change next year the Bankingformat to the SEPA Format. All peoples and companies must change the bankingssoftware and the costumer data form acountnummers in the new IBAN and BIC numbers. See: http://www.arma-it.de/shop/artikelueber.php?wgruppeid=211&wgruppe_offen=211 Functions: - generate SEPA XML'S - Calc IBAN - BIC Database (DE,AT and CH) Questions: vertrieb@arma-it.de PS: Bankinssoftware for Develpoers (Germany only) http://www.arma-it.de/shop/artikelueber.php?wgruppeid=212&wgruppe_offen=212 El 26/10/13 21:38, A...

Delphi XE7 : Product or License Validation Error [Edit] #2
Hello, I'am very angry. I was coding on my Delphi XE7 Enterprise registered since 1 month on a Vmware workstation 11 on Windows 7 when IDE suddenly existed/closed (without save my source) and open a page "Product or License Validation Error " : http://www.embarcadero.com/product-validation-error So I have lost all my modification in my source !!! When I restart Delphi XE7 all it's ok : Registration always ok. Now I would like to know if it is possible to work on a legal/registered Delphi XE7 or time to migrate to Visual Studio ? Now Embarcadero/Delphi it is 2...

Delphi XE5 on android Gyroscope, Accelerometer not work (angle) [Edit]
Device: - Google Nexus 7 - Cubot GT99 http://sourceforge.net/p/radstudiodemos/code/HEAD/tree/branches/RadStudio_XE5/MobileCodeSnippets/Gyroscope/ - does not rotate http://sourceforge.net/p/radstudiodemos/code/HEAD/tree/branches/RadStudio_XE5/MobileCodeSnippets/Accelerometer/ - work: Acceleration X, Acceleration Y, Acceleration Z - Angle X, Angle Y, Angle Z, Speed not visible Please FIX or I can not set up permissions? P\S http://www.youtube.com/watch?v=NJ8UQiBZfIc ( It also shows on the listed device ) I Edited by: ceollihuk ceollihuk on Nov 16, 2013 2:42 AM ...

Delphi XE7
I opened an XE6 project with banner ads in Delphi XE7 and the app crashes on device when run. I have not tested on iOS. Also, I have properly set the android ad option in the project entitlement options. Can anyone help throw any light on this and suggest how to fix this and not make the app crash? When I create a new project with ads banner in XE7, it runs properly. Also, I am not able to open the sample mobile app CapitalIAP that has banner ads - the XE7 IDE complains that the list box has no width property. Any help is appreciated... Edited by: Karu Kaarigar on Dec 20, 2014 5:10 PM ...

Delphi XE7 : Product or License Validation Error [Edit] #2
Hello, I'am very angry. I was coding on my Delphi XE7 Enterprise registered since 1 month on a Vmware workstation 11 on Windows 7 when IDE suddenly it's exist/close (without save my source) and open a page "Product or License Validation Error " : http://www.embarcadero.com/product-validation-error So I have lost all my modification in my source !!! When I restart Delphi XE7 all it's ok : Registration always ok. Now I would like to know if it is possible to work on a legal/registered Delphi XE7 or time to migrate to Visual Studio ? Now Embarcadero/Delphi i...

send sms android app delphi xe7 question [Edit]
i have written following code for send sms on delphi xe7 but i have following error { java.lang.securityexception: sending sms message : uid10176 does not have android.permission.send_sms } { unit Unit1; interface uses System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls, FMX.Helpers.Android, Androidapi.JNI.GraphicsContentViewText, Androidapi.JNI.Net, Androidapi.JNI.JavaTypes, Androidapi.JNI.Telephony, Androidapi.Helpers; type TForm1 = c...

Does Delphi XE5 firemonkey work on current Samsung tablets? [Edit]
I am being told that Delphi XE5 with firemonkey will not work on the current range of Samsung tablets even if they have Android 4 is that true? If so I will be very disappointed having invested thousands of pounds and a few hundred hours to adopt the technology on the promise I can now deploy to Android mobile devices. When I run even the most simple Hello World app I simply get a black screen on my brand new Samsung tablet. I am told it only works on Android devices with a ARMv7 CPU supporting NEON instruction sets. If this is the case developers need to know that I have been told today ...

Delphi XE7 : Product or License Validation Error [Edit] #2
Hello, I'am very angry. I was coding on my Delphi XE7 Enterprise registered since 1 month on a Vmware workstation 11 on Windows 7 when suddenly it's exist (without save my source) and open a page "Product or License Validation Error " : http://www.embarcadero.com/product-validation-error So I have lost all my modification in my source !!! When I restart Delphi XE7 all it's ok : Registration always ok. Now I would like to know if it is possible to work on a legal/registered Delphi XE7 or time to migrate to Visual Studio ? Now Embarcadero/Delphi it is 2 new...

Web resources about - PHP -> JSON ->Zlib -> Delphi XE7 [win32 -> work | android -> No mapping ] [Edit] #2 - embarcadero.delphi.firemonkey

Resources last updated: 11/22/2015 1:02:36 PM