How to Handle Long URLs
One of the issues with Internet Explorer is that it has a 2048 character limit for urls. This is problematic for long GET requests, since the url could be truncated and cause an invalid request.
The Long URL Service provides a way around this by allowing you to provide the request in parts shorter than the character limit, and then will make your request for you at the end and provide back the response.
We've created a simple javascript library to handle the legwork, which you can get here: mqa.longurl.js. This should allow anyone to access our services using JSONP, without worrying about how long the urls are.
Note: This currently does not work with a URL returning an image (eg: Static Map Service)
Service Documentation
Service URL: /longurl/v1/
Parameters
| Name | Description |
|---|---|
| data | the partial chunk of the url to send |
| callback | the name of the callback function to return intermediate responses |
| id | the id of long url session (returned by server after the first request) |
| done | append "done=true" as a query parameter when sending the final url chunk,
the server will respond with the actual response of the long url provided |
Response
If the partial url chunk is received and stored successfully, the server will respond with a json response wrapped in the provided callback. The json response contains a single property, which is the id of the current session.
Example: myCallbackFunction({id: "3622c3b8-a2f4-4506-911d-81426345427b"});
If for some reason there's an error along the way, the server will respond with a json response wrapped in the provided callback. The json response contains a single property, error, containing the error message of what went wrong.
Example: myCallbackFunction({error: 'URL provided couldn't be retrieved.
/some/bad/url/here.html'});
Javascript Library Documentation
MQA.LongURL
Constructor Parameters:
- url - the actual url for the service to call
- options - an object of key/value pairs, to override the library setting defaults
- maxLength - change the max character length of url parts to send to the service, defaults to 1900
- server - the host:port of the Long URL service, defaults to www.mapquestapi.com
Methods:
- send - call to execute the MQA.LongURL instance