Here's a hybrid solution using similar ideas from other answers:
You can write a dead simple HTTP server that listens on "localhost: 80" (or regardless of which port is on the server you are targeting), and direct your application to that host instead, dropping the host name from the requests. On your local server there is a link to the actual remote server and the following is done:
- If ONLINE sends the request as it is to the real server, receives a response, it saves it locally or in a cache in memory pointed to by the request URL, or a file with the URL as its identifier (marked accordingly)
- If OFFLINE, searches for a request in the cache (in memory or file system) and returns the contents from the cache
This is similar to the recording / playback mode that @ nicholas.hauschild says.
Now you can simply launch the application once when ONLINE, as a result of which your local server will delete the requests that it issues against the real server. Then, when you launch the OFFLINE application, it simply returns this cached content, and then when the same URL is issued.
Hope this helps.
source share