Android的如何模拟脱机演示HTTP通信 [英] Android How To Simulate HTTP Communication for Offline Demo

查看:128
本文介绍了Android的如何模拟脱机演示HTTP通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Android应用程序,它使用了几乎所有的操作HTTP通讯。我希望能够不受莫名其妙地重播HTTP交换连接到互联网演示。如何才能做到这一点?所以我想以某种方式就像模仿对象,但真正模拟HTTP会话,所以我可以随时在演示或离线应用程序。这是真正能够做一个非常酷的事情。既然你可以很容易地,可靠地演示应用。有谁知道我怎么能做到这一点。复制整个服务器端仅仅是不是一个选择它得到了太多的东西。其重要的是不要只显示截屏,但实际的数据交换。我只是想能够直通应用程序和重放运行。也许调试也是如此。谢谢

I have an Android App which uses http communication for nearly every operation. I want to be able to demo without connection to the internet by somehow replaying the http exchange. How can this be done? So I want to somehow almost like mock objects but really mock http session so I can always demo the app on or offline. This is really a very cool thing to be able to do. Since you can demo the app easily and reliably. Does anyone know how I could do this. Replicating the whole server side is just not an options its got too much stuff. Its important not to just show screencast but the real data exchange. I just want to be able to run thru the app and replay. Maybe debug as well. Thanks

推荐答案

下面是一个使用类似的想法从其他答案一种混合解决方案:

Here's a hybrid solution using similar ideas from other answers:

您可以编写一个侦听死简单的HTTP服务器的本地主机:80(或任何端口是在服务器上您的目标),并通过而不是从请求分解出的主机名指向你的应用程序到该主机。本地服务器具有实际的远程服务器的引用并执行以下操作:

You could write a dead simple HTTP server that listens on "localhost:80" (or whatever the port is on the server you're targeting) and point your application to this host instead by factoring out the host name from requests. Your local server has a reference to the actual remote server and does the following:


  • 如果在线,请求转发的,是真正的服务器,获取响应,将它保存在本地或者通过请求URL或与该URL作为标识符(适当地被改写的)命名的文件键入一个内存缓存

  • 如果离线,查找在其(在内存或文件系统)的高速缓存的请求,并从高速缓存返回的内容,而不是

这是一种像录制/播放模式的@ nicholas.hauschild说。

This is kind of like the record/playback mode that @nicholas.hauschild says.

现在你可以运行你的应用程序时,一次网上,引起本地主机服务器保存离开它发出对真实服务器的请求。然后,当你运行你的应用程序脱机状态,只是返回这些缓存的内容,而不是只要使用相同的网址发出。

Now you can just run your app once when ONLINE, causing your localhost server to save away requests that it issues against the real server. Then when you run your app OFFLINE, it just returns these cached contents instead whenever the same URLs are issued.

希望这有助于。

这篇关于Android的如何模拟脱机演示HTTP通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆