Asynchronous HTTP Client for Java

后端 未结 13 1630
梦谈多话
梦谈多话 2020-12-01 05:01

As a relative newbie in the Java world, I am finding many things frustratingly obtuse to accomplish that are relatively trivial in many other frameworks. A primary example i

13条回答
  •  甜味超标
    2020-12-01 05:16

    So, it is probably worth considering that actionscript and Java don't server the same niche. For example, Java does make some things more tedious - but usually that is to give the user more options in how, for example, an HTTP connection is executed, whereas actionscript might abstract details or possible errors away for ease of use. But, your point still stands.

    I myself am not aware of an asynchronous HTTP client for Java. Alex Martelli's answer talks about Java's NIO, which is a good answer if you are interested in implementing the HTTP protocol in your own code. NIO will let you use sockets to connect to the web server - but then you have to manually create your own GET requests and parse the incoming HTTP headers/data.

    Another option is to use the java.net.URL classes - and you can find many tutorials for those online and on stackoverflow. You can wrap those in threads - so your java program has multiple threads of execution.

    But then you run into the problem of synchronization. Which I agree, is a pain, but then it offers a more granular level of flexibility.

    (I realize that this doesn't answer your question - and if anybody actually knows of a java facility to do asynchronous http requests, I'd be interested to know!)

提交回复
热议问题