Java中的异步HTTP请求 [英] asynchronous HTTP request in java
问题描述
如何在Java中发送异步HTTP GET/POST请求而不等待/读取响应?我不想使用任何第三方库..
How to send asynchronous HTTP GET/POST request in java without waiting/reading response ?I don't want to use any third party libraries ..
推荐答案
If you're not interested in reading the response at all you can just use URL.openStream() to create a connection and then immediately close the socket (or ignore it and let it time out, if you feel like being mean to the server). This isn't strictly asynchronous, but it will be quite a bit faster than any approach that relies upon fetching and parsing the server's response.
当然,可以通过手动或使用 java.util.concurrent
中可用的实用程序将 openStream()
调用卸载到另一个线程来使其异步.
This can of course be made asynchronous by offloading the openStream()
calls to another thread, either manually or by using the utilities available in java.util.concurrent
.
这篇关于Java中的异步HTTP请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!