tags:

views:

117

answers:

6

I have a really long string that I need to pass in a URL, say 10,000 characters. Anyone know a good way to shorten it to under 2,000 chars, and then on a server somehow get the original back?

This is Objective-C talking to Ruby, but that shouldn't matter.

+5  A: 

Can you post the data? If you use GET the max length of a url is around 4000 characters. If you POST it you have no constraints (except timeouts memory etc)

This article talks about doing a post from objective-c

Byron Whitlock
+1 for not answering the question, but rather giving a solution to the (likely) real problem
Ben S
wow, i'm a little slow this morning. of course. thanks for the quick reply.so this trigger an interesting thought process. without using a db, does anyone know a two-way function that can shrink a string and then get it back?
Nader
If you do a POST, You can always enable HTTP compression. That will transparently compress the whole connection so it happens faster.
Byron Whitlock
+1  A: 

Are you sure you have to pass it in as a URL? Maybe POST-Data or Session would be more appropriate? otherwise you could store the string in a database and return the key of the inserted record as a URL Parameter. If this is a security concern (as people can just change the number if it is an integer key), you could create a UUID as key.

Michael Stum
A: 

You can try running it through Base64. If the string is guaranteed to have only a subset of possible characters -- for example, [a-zA-Z0-9] -- it can be shortened even more by converting these to unique ordinals and using a higher base encoding.

But it would probably be easier to just use POST.

John Millikin
+1  A: 

Store it in a database and then just pass the id of the string in the url.

Buggabill
A: 

Well, compress it and Base64 encode the result. If the string has a very specific format, a custom encoding could even yield a better compression. Can you give an example?

Daniel Brückner
@Daniel: Depending on the compressibility of the data he could end up with a longer string than he started with. Also there is no guarantee he will get the 5:1 compression he needs to accomplish the task as described.
Grant Wagner
That is why I asked for an example... ;)
Daniel Brückner
A: 

I would persist this information to a database (or any other persistence source) and then pass a reference to it in the URL.

Both source and destination will require access to the database, but that isn't an issue most of the time.

Matthew Vines