Reputation: 5595
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.
Upvotes: 2
Views: 705
Reputation: 27561
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.
Upvotes: 0
Reputation: 59655
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?
Upvotes: 0
Reputation: 13901
Store it in a database and then just pass the id of the string in the url.
Upvotes: 1
Reputation: 200826
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.
Upvotes: 0
Reputation: 180954
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.
Upvotes: 1
Reputation: 53871
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
Upvotes: 5