简体   繁体   English

我可以在我的 java 应用程序中放置一个 HTTP 代理服务来拦截所有 HTTP 请求并更改标头吗?

[英]Can I put an HTTP proxy service in my java app to intercept all HTTP requests and change the headers?

I am writing an android app in java, and would like to intercept all HTTP traffic from its outgoing requests and change the user agent from the header. I know there are tools to do this from separate apps/programs like Charles' Proxy, but can I do this from within the app itself?我正在 java 中编写一个 android 应用程序,并希望从其传出请求中拦截所有 HTTP 流量,并从 header 更改用户代理。我知道有一些工具可以从单独的应用程序/程序(如 Charles 的代理)中执行此操作,但可以我从应用程序本身内部执行此操作? Would I be able to register a service in my app for this?我可以为此在我的应用程序中注册服务吗? If so, do you have any links I can reference to get started or have any tips?如果是这样,您是否有任何我可以参考的链接或有任何提示? I am a novice coder, so anything at all is appreciated.我是一名新手编码员,所以任何事情都会受到赞赏。 Thank you.谢谢你。

Do you use OkHttp to make requests?你使用 OkHttp 发送请求吗? If so, the library has a powerful mechanism of interceptors to do exactly what you want.如果是这样,库有一个强大的拦截器机制来做你想做的事。

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

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