简体   繁体   English

为Android应用程序编写代理

[英]Writing a proxy for an android application

I have an android application which sends information to a server in particular it sends some stats to check the normal use that users do with the app. 我有一个Android应用程序,它将信息发送到服务器,尤其是它发送一些统计信息来检查用户对该应用程序的正常使用。 For example if they click a button to see a specific page a stat is sent to the server specifying a series of informations like the model of the phone, the page requested, the version of android ecc ecc. 例如,如果他们单击按钮以查看特定页面,则会将统计信息发送到服务器,以指定一系列信息,例如手机型号,请求的页面以及android ecc ecc的版本。 These informations are later visible using splunk http://www.splunk.com/ . 这些信息以后可以使用splunk http://www.splunk.com/看到。 Now my problem is, for each event sent by my app, I should be able to say if the event was correclty sent to the server or not. 现在我的问题是,对于我的应用发送的每个事件,我应该能够说出该事件是否正确发送到服务器。 My idea is to develop a proxy that can intercept the requests made by my app to the server and listen the response, like Charles proxy does. 我的想法是开发一个代理,该代理可以像Charles代理一样拦截我的应用程序对服务器的请求并侦听响应。 The problem is I don't know where to start. 问题是我不知道从哪里开始。 Anyone can suggest me how could accomplish this task? 任何人都可以建议我如何完成这项任务? Thanks 谢谢

Well I think you could add code to your application so that, when you send your data, you get the HTTP reply and check if code is 200 (Which stand for OK responde from server). 好吧,我认为您可以向应用程序中添加代码,以便在发送数据时,您将收到HTTP答复,并检查代码是否为200(代表服务器的OK Responsee)。 If so you know that your request went fine, if not(different reply code) you treat it as an error. 如果是这样,您就知道您的请求可以正常进行,如果不是(不同的回复代码),则将其视为错误。

You will have to check if your server is responding properly, for an error and an OK message. 您将必须检查服务器是否响应正确,是否有错误和OK消息。

See also HTTP STATUS CODES 另请参见HTTP状态代码

A good idea would be to use the Proxy Design Pattern for your extra code. 一个好主意是为您的额外代码使用代理设计模式

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM