简体   繁体   English

如何在java中获取HttpURLConnection使用的套接字

[英]How to get the socket used by HttpURLConnection in java

There is a socket which HttpURLConnection use internally to send data. HttpURLConnection在内部使用一个套接字来发送数据。 I know it is now visible from outside, but I am wondering if there's any workaround so that I could get access to this socket (without changing the implementation of HttpURLConnection)? 我知道它现在可以从外面看到,但我想知道是否有任何解决方法,以便我可以访问此套接字(不更改HttpURLConnection的实现)? I need this hack to do some instrumentation. 我需要这个黑客做一些仪器。

Thanks a lot. 非常感谢。

Sockets are created by Socket Factories . 套接字由Socket Factories创建。 You can write your own SocketFactory, delegating to the original socket factory. 您可以编写自己的SocketFactory,委托给原始套接字工厂。 In your Socket Factory, you can manipulate the socket. 在Socket Factory中,您可以操作套接字。 That's one way I can think of for you to get access to the socket, but I'm going to warn you in advance - it's not going to be pretty. 这是我可以想到让你访问套接字的一种方式,但我会提前警告你 - 它不会很漂亮。

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

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