Post non-alphanumerical characters using network.request() doesn't work on Android

Hello,

 

I am posting some text using network.request() method. It works perfect for alphanumerical characters(English letters…), But when I post Arabic or Russian (special characters), I get this error:

 

I/System.out(27394): ERROR: expected 385 bytes but received 393

 

The number of bytes depends on how big is the text, but the difference(ie: 393-385) is consistent and reflects the number of letters in the text.

 

It works fine when tested on iphone and mac simulator though the difference in bytes, but it fails in Android!

I’m having  a little trouble making this happen … could you add an reproducible case to the bug you filed (or file a new bug)?

Thanks!

Hi,

If you run this snippet from an Android device (Tested in Galaxy S2, S3 and S4):

[lua]

local function networkListener( event )

        if ( event.isError ) then

                print( “Network error!”)

        else

                print ( "RESPONSE: " … event.response )

        end

end

local headers = {}

headers[“Content-Type”] = “application/x-www-form-urlencoded”

headers[“Accept-Language”] = “en-US”

local body = “name=جحخه”

local params = {}

params.headers = headers

params.body = body

network.request( “http://66.96.147.105”, “POST”, networkListener, params)

[/lua]

You will get the ERROR shown below displayed on the terminal (I use this command to print the logs: adb logcat Corona:v*:S):

I/System.out(23994): ERROR: expected 9 bytes but received 13

But if you run the same snippet from an iPhone device, it works fine an it displays a proper response:

RESPONSE: <!DOCTYPE HTML PUBLIC “-//IETF//DTD HTML 2.0//EN”>

<html><head>

<title>403 Forbidden</title>

</head><body>

<h1>Forbidden</h1>

<p>You don’t have permission to access /

on this server.</p>

</body></html>

Can you please advice?

Thanks,

I’m still trying to figure out exactly why Android is objecting to the request but in the meantime specifying a binary body type seems to make it work for me:

params.bodyType = "binary"&nbsp;

This is fixed in Daily Build 2013.1147 (the Content-Length of POST requests was being miscalculated when there were multi-byte characters in a string).

Great! thanks for your support :slight_smile:

I’m having  a little trouble making this happen … could you add an reproducible case to the bug you filed (or file a new bug)?

Thanks!

Hi,

If you run this snippet from an Android device (Tested in Galaxy S2, S3 and S4):

[lua]

local function networkListener( event )

        if ( event.isError ) then

                print( “Network error!”)

        else

                print ( "RESPONSE: " … event.response )

        end

end

local headers = {}

headers[“Content-Type”] = “application/x-www-form-urlencoded”

headers[“Accept-Language”] = “en-US”

local body = “name=جحخه”

local params = {}

params.headers = headers

params.body = body

network.request( “http://66.96.147.105”, “POST”, networkListener, params)

[/lua]

You will get the ERROR shown below displayed on the terminal (I use this command to print the logs: adb logcat Corona:v*:S):

I/System.out(23994): ERROR: expected 9 bytes but received 13

But if you run the same snippet from an iPhone device, it works fine an it displays a proper response:

RESPONSE: <!DOCTYPE HTML PUBLIC “-//IETF//DTD HTML 2.0//EN”>

<html><head>

<title>403 Forbidden</title>

</head><body>

<h1>Forbidden</h1>

<p>You don’t have permission to access /

on this server.</p>

</body></html>

Can you please advice?

Thanks,

I’m still trying to figure out exactly why Android is objecting to the request but in the meantime specifying a binary body type seems to make it work for me:

params.bodyType = "binary"&nbsp;

This is fixed in Daily Build 2013.1147 (the Content-Length of POST requests was being miscalculated when there were multi-byte characters in a string).

Great! thanks for your support :slight_smile:

Thanks a lot! This kind of information would be of terrible help in the docs … took me forever to find this!

On Simulator this is not required and is a really unpleasant surprise to debug this on the device.

You can click the buttons at the bottom of the page where you can like, like but… or hate the docs.  We do take your comments you make there and apply them when they make sense.  I would say adding a gotcha about UTF-8 text needs to be sent in binary mode would be a good addition.

Rob

Well Perry said it was fixed so that would only apply to pre 2013.1147 builds.

Thanks a lot! This kind of information would be of terrible help in the docs … took me forever to find this!

On Simulator this is not required and is a really unpleasant surprise to debug this on the device.

You can click the buttons at the bottom of the page where you can like, like but… or hate the docs.  We do take your comments you make there and apply them when they make sense.  I would say adding a gotcha about UTF-8 text needs to be sent in binary mode would be a good addition.

Rob

Well Perry said it was fixed so that would only apply to pre 2013.1147 builds.