What is "mime"

I’ve read something in a post made by Rob Miracle

http://omnigeek.robmiracle.com/2012/04/15/using-corona-sdk-with-rest-api-services/

I notice there is a a

local mime = require("mime")

I can’t find any of it in the corona docs, what is it? what its purpose?

MIME - Multipurpose Internet Mail Extension.  See: http://en.wikipedia.org/wiki/MIME

Its the standard way that non-text objects get encoded so they can be safely transmitted by email.  Many Internet services uses MIME encodeing/decoding to assure that binary data like images, audio, movies, spreadsheets, PDFs etc, can pass safely through various internet services like web servers, gopher servers, FTP and of course Email.

The “mime.lua” isn’t really part of Corona SDK.  It’s part of the standard Lua Sockets implementation, which Corona SDK supports.    Its documented on the Lua site a part of the Sockets library:  http://w3.impa.br/~diego/software/luasocket/old/luasocket-2.0-beta/mime.html

Rob

basically it translates images to binaries? I saw in your post that you use this in the Username and password, how does it work?

Well base64 encoding takes your binary and converts it to ASCII so it can be safely transmitted.  Then when you get the base64 embedded data, you run it through a base64 decode process to turn it back into binary data.

However in the blog post, I’m doing it to obscure the username and password, so that people snooping with a packet sniffer won’t see the username and password in the clear.  Obscured data does some protection but it’s not as good as a real encryption method.

oh okay thanks though :slight_smile:

Rob how can you I display the “?playername=my%20name&password=letmein” in your link? I don’t know how to make that appear, I copied your code but still the “?” and the rest won’t appear

I’m not sure I understand your question.  Where do you want to display the values?  In your Corona App?  Is this data you expect back from the server?

That code is intended to be sent to a web server script expecting HTTP GET type requests.  That script would then need to parse that string to convert the data into key-value pairs.  For instance, in PHP you would end up with a variable called $playername that had the value of “my name” and a variable called $password with the value of “letmein”.  You have to know PHP (or whatever other web scripting language of your choice) well enough to get that string of data and turn it into something the script can use.

Then if you expect the script to send something back, then it’s your responsibility to take that text which is returned in the network.request()'s event handling function as event.response and parse it into data you can use.  The tutorial recommends having the server output JSON data since Corona SDK has a JSON parser that turns it into table data for you.

If these concepts are foreign to you, then you need to spend some time learning web scripting (I recommend PHP for things like this) and how web servers handle requests (so that you know what a GET request is, what a POST request is, how to format the data properly for each) and then learn  how your scripting language of choice knows how to access that data. 

Only then will this begin to make sense.

Rob

yeah, I had a background on PHP, the only thing is in my server whenever I reload/load it it only sends me the

http://www.testing.com/testing.php(sample) it doesn’t give me the ?playername=my%20name&password=letmein part,  I only know scripting, but I haven’t try URL things. Based on my understanding on your guide. when the browser finds in your script a “GET” it will automatically create a link that has the ?playername etc. part or all things that needs source from other things.

Those values should be in the $_GET[] array as key value pairs, i.e.:

$playername = $_GET[“playername”];

$password = $_GET[“password”];

If not, you may not be sending them correctly when you make your network.request() in Corona.  Perhaps you could post that code?

MIME - Multipurpose Internet Mail Extension.  See: http://en.wikipedia.org/wiki/MIME

Its the standard way that non-text objects get encoded so they can be safely transmitted by email.  Many Internet services uses MIME encodeing/decoding to assure that binary data like images, audio, movies, spreadsheets, PDFs etc, can pass safely through various internet services like web servers, gopher servers, FTP and of course Email.

The “mime.lua” isn’t really part of Corona SDK.  It’s part of the standard Lua Sockets implementation, which Corona SDK supports.    Its documented on the Lua site a part of the Sockets library:  http://w3.impa.br/~diego/software/luasocket/old/luasocket-2.0-beta/mime.html

Rob

basically it translates images to binaries? I saw in your post that you use this in the Username and password, how does it work?

Well base64 encoding takes your binary and converts it to ASCII so it can be safely transmitted.  Then when you get the base64 embedded data, you run it through a base64 decode process to turn it back into binary data.

However in the blog post, I’m doing it to obscure the username and password, so that people snooping with a packet sniffer won’t see the username and password in the clear.  Obscured data does some protection but it’s not as good as a real encryption method.

oh okay thanks though :slight_smile:

Rob how can you I display the “?playername=my%20name&password=letmein” in your link? I don’t know how to make that appear, I copied your code but still the “?” and the rest won’t appear

I’m not sure I understand your question.  Where do you want to display the values?  In your Corona App?  Is this data you expect back from the server?

That code is intended to be sent to a web server script expecting HTTP GET type requests.  That script would then need to parse that string to convert the data into key-value pairs.  For instance, in PHP you would end up with a variable called $playername that had the value of “my name” and a variable called $password with the value of “letmein”.  You have to know PHP (or whatever other web scripting language of your choice) well enough to get that string of data and turn it into something the script can use.

Then if you expect the script to send something back, then it’s your responsibility to take that text which is returned in the network.request()'s event handling function as event.response and parse it into data you can use.  The tutorial recommends having the server output JSON data since Corona SDK has a JSON parser that turns it into table data for you.

If these concepts are foreign to you, then you need to spend some time learning web scripting (I recommend PHP for things like this) and how web servers handle requests (so that you know what a GET request is, what a POST request is, how to format the data properly for each) and then learn  how your scripting language of choice knows how to access that data. 

Only then will this begin to make sense.

Rob

yeah, I had a background on PHP, the only thing is in my server whenever I reload/load it it only sends me the

http://www.testing.com/testing.php(sample) it doesn’t give me the ?playername=my%20name&password=letmein part,  I only know scripting, but I haven’t try URL things. Based on my understanding on your guide. when the browser finds in your script a “GET” it will automatically create a link that has the ?playername etc. part or all things that needs source from other things.

Those values should be in the $_GET[] array as key value pairs, i.e.:

$playername = $_GET[“playername”];

$password = $_GET[“password”];

If not, you may not be sending them correctly when you make your network.request() in Corona.  Perhaps you could post that code?