简体   繁体   English

如何使用okio / okhttp解码http请求数据包

[英]How to decode a http request packet with okio/okhttp

Can I use Okio and/or OkHTTP to decode a packet read from ParcelFileDescriptor ? 我可以使用Okio和/或OkHTTP解码从ParcelFileDescriptor读取的数据包吗?

I'm trying to write a VpnService based ad-blocker on android. 我正在尝试在Android上编写基于VpnService的广告拦截器。

I've found a few open source projects using VpnService ( NetGuard , NetKnight ), so I could learn from them. 我发现了一些使用VpnService开源项目( NetGuardNetKnight ),因此我可以向他们学习。

And I known OkHTTP could make a request using just url and method , which means it could understood some thing like GET http://stackoverflow.com Http/1.1 , and transform it to a real TCP/IP based request, even decode response. 我知道OkHTTP可以仅使用urlmethod发出请求,这意味着它可以理解GET http://stackoverflow.com Http/1.1 ,并将其转换为基于真实TCP / IP的请求,甚至可以解码响应。 So I tried to read some source code of Okio to found out what it does, but failed. 因此,我尝试阅读Okio的一些源代码以了解其功能,但是失败了。

So I was wondering if I could use Okio's component to decode/encode TCP/IP packets? 所以我想知道是否可以使用Okio的组件对TCP / IP数据包进行解码/编码?

Yes. 是。 Create a Socket using the normal APIs, then use Okio.source(Socket) and Okio.sink(Socket) to get streams from it. 使用常规API创建一个Socket,然后使用Okio.source(Socket)Okio.sink(Socket)从中获取流。 Also don't forget that you can buffer these streams with Okio.buffer() . 同样不要忘记,您可以使用Okio.buffer()缓冲这些流。

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

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