发送Web请求,而不是等待响应 [英] Sending web request and not waiting for response
问题描述
我使用的使用HttpURLConnection类的时刻发送HTTP GET请求的这种方式。
( http://www.mkyong.com / JAVA /如何对发送-HTTP请求-的getPost-在爪哇/ )
I am using this way of sending http get requests at the moment using HttpURLConnection. (http://www.mkyong.com/java/how-to-send-http-request-getpost-in-java/)
我不知道我将如何去没有收到请求的响应,甚至不承认它在所有和公正所需要的要求以最快的速度发射了地,我怎么能做到这一点?
I was wondering how would I go about not receiving the response from the request or even acknowledge it at all and just needed the request to be fired off as fast as possible how could I achieve this?
感谢。
推荐答案
您需要的是射后不理的语义,没有直接关系的HTTP请求,而更多的线程。只要启动不管你的任务是,在一个新的线程
What you need is a "fire and forget" semantic, not directly related to http request, rather more to threads. Simply launch whatever your task is, in a new thread
Thread thread = new Thread(new Runnable(){
@Override
public void run(){
HttpURLConnectionExample http = new HttpURLConnectionExample();
System.out.println("Testing 1 - Send Http GET request");
http.sendGet();
}
});
thread.start();
这篇关于发送Web请求,而不是等待响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!