Page 1 of 1

Post Data works with LC 6.6.5 but not 7.0.1

Posted: Sat Feb 14, 2015 9:16 pm
by trags3
I have an app that was working fine on a borrowed Macbook Pro last Aug. I have had an interesting time getting it to work on my Macbook Air. Files that I compiled and installed on LG G2 (Android), iPhone 4S, iPhone 5, and Samsung Note (Android) all worked fine when compiled with LC 6. something. (not exactly sure which version.)

With the Macbook Air, after sorting thru the hoops and hurdles presented to a newbie transfering certificates and profiles etc. from one computer to another, I have finally found some code that always worked before but now doesn't work at all with LC 7.0.1. The same code on the same Mac works fine with LC 6.6.5. I haven't tried any other versions yet.

I log in to my server, search a small database table to make sure that a username and password are contained in the database on the server. If the record is found successfully then the app continues to execute.

This all works fine with LC 6.6.5 on the Macbook Air as well as the 4 devices that have the app on them. It also works fine in the simulator and in the IDE.

tOutput is some HTML mumbo jumbo when I run with LC 7.0.1 :(

Here is the code:

show image "wait.gif"
put fld "userEmail" of cd "Login Page" into tuvar
put tuvar into tArray["useremail"]

put fld "passwordField" of cd "Login Page" into tpasvar
put tpasvar into tArray["upassword"]

put "data=" & URLEncode(base64Encode(arrayEncode(tArray))) into tData
put URLEncode("myapi username") into tApiUser
put URLEncode("myapi password") into tApiPass
show image "wait.gif"
post tData to URL ("https://" & tApiUser & ":" & tApiPass & "@ssl-myserversignin.com/~my serveraccount/api/login.lc")
put it into tOutput

tOutput is "<pre> row 3, col 1: arrayDecode: failure ......

The error occurs in the very first line of code (row 3) in the login.lc code.

Here is that line od code on the server:

<?lc

put arrayDecode (base64Decode(urlDecode($_POST["data"]))) into tArray

Any Ideas as to what I might be doing wrong?

Thanks.
Tom

Re: Post Data works with LC 6.6.5 but not 7.0.1

Posted: Sat Feb 14, 2015 9:32 pm
by FourthWorld
If your server engine version is earlier than 7.0, the problem may be that by default the arrayEncode output now uses a different Unicode-safe format in v7.x.

To accommodate interoperability with earlier engines, the arrayEncode function now includes an optional second argument to specify the compatible version number for the output format. Any number below 7 will use the older format. e.g.:

Code: Select all

put arrayEncode(tSomeArray, "6.7") into tOutput
Conveniently, it seems that some versions of 6.x (at least 6.7 and later) allow the use of that second version argument as well. It doesn't do anything in versions before 7, since of course earlier versions only have one encoded array format. But at least the v6.7 engine it won't complain if you include it, so if you need to move code between 6.7 and 7.x you can do so without difficulty with this second argument.

Tech detail: array elements are flagged internally with op codes to determine the element's data type. In the older format, when an element was an array the value of 0x05, and under the new format it appears to be 0x06. Since the output of arrayEncode is itself effectively an array element, the first byte of that output will be that op code number. So if you need to determine the encoding version you can use byteToNum to get the value of the first byte of the encodeArray output.

But in practical use you'll probably never need to do that, since v7 supports both formats and will automatically detect which is one is used when it attempts arrayDecode.

Re: Post Data works with LC 6.6.5 but not 7.0.1

Posted: Sat Feb 14, 2015 9:45 pm
by trags3
Thanks Richard,
I will try that in a little while.
I'm not sure what the Server version is but it's probably not 7.
Thanks again,

Tom

Re: Post Data works with LC 6.6.5 but not 7.0.1

Posted: Mon Feb 16, 2015 6:35 pm
by trags3
Richard, Thank You.
That solved the problem.
Tom

Re: Post Data works with LC 6.6.5 but not 7.0.1

Posted: Mon May 11, 2015 6:49 pm
by trags3
In the last 3 or 4 weeks my app stopped working when sending a JPG file as an attachment (with the server)
Here is the code used to generate the Picture (snapshot of a card)

export snapshot from rect "0,0,400,725" of this card to FILE (specialFolderPath("documents") & "/sellnet.jpg") as JPEG

Here is the code that I use to post to the server to email the jpg file using the server to sent the email.

put "sellnet.jpg" into tArray["attachments"]["1"]["name"]
put "image/jpeg" into tArray["attachments"]["1"]["type"]

put URL ("binfile:" & specialFolderPath("documents") & "/" & \ tArray["attachments"]["1"]["name"]) into tData

put base64Encode(tData) into tArray["attachments"]["1"]["base64_data"]

put "data=" & URLEncode(base64Encode(arrayEncode(tArray, "6.7"))) into tData
put URLEncode("myApiUserName") into tApiUser
put URLEncode("myApiUserPW") into tApiPass

show image "wait.gif"
post tData to URL ("https://" & tApiUser & ":" & tApiPass & \ "@ssl-myserveraccountcom/~myaccount/api/seller_mail.lc")

The "6.7" in the arrayEncode function was what fixed my original communication problem.

I am using LC 7.0.3 and everything was working until a few weeks ago.
I havent made any changes to this code or the server code (seller_mail.lc). It just quit working. Emails that don't have an attaxchment still work.

Thanks
Tom

Re: Post Data works with LC 6.6.5 but not 7.0.1

Posted: Tue May 12, 2015 11:08 pm
by FourthWorld
Any better luck with the current version, v7.0.4?

Re: Post Data works with LC 6.6.5 but not 7.0.1

Posted: Wed May 13, 2015 4:56 pm
by trags3
Thanks Richard, It works in the IDE with LC 7.0.4. I can't build standalone yet as I don't have Xcode 6.2 installed. I reverted to 6.1 because I had some issues wit 6.2 before. I'll reinstall but it looks like that fixed my problems. :D

Tom