| 注册
请输入搜索内容

热门搜索

Java Linux MySQL PHP JavaScript Hibernate jQuery Nginx
jopen
11年前发布

异步HTTP和WebSocket的Java客户端:Async Http Client

异步HTTP和WebSocket的客户端库Java类库。允许Java应用程序轻松地执行HTTP请求并异步处理HTTP响应。该库还支持WebSocket协议。Async Http Client使用简单。

import com.ning.http.client.*;  import java.util.concurrent.Future;    AsyncHttpClient c = new AsyncHttpClient();  Future<String> f = c.prepareGet("http://www.ning.com/").execute(new AsyncHandler<String>() {      private ByteArrayOutputStream bytes = new ByteArrayOutputStream();        @Override      public STATE onStatusReceived(HttpResponseStatus status) throws Exception {          int statusCode = status.getStatusCode();          // The Status have been read          // If you don't want to read the headers,body or stop processing the response          if (statusCode >= 500) {              return STATE.ABORT;          }      }        @Override      public STATE onHeadersReceived(HttpResponseHeaders h) throws Exception {          Headers headers = h.getHeaders();           // The headers have been read           // If you don't want to read the body, or stop processing the response           return STATE.ABORT;      }        @Override      public STATE onBodyPartReceived(HttpResponseBodyPart bodyPart) throws Exception {           bytes.write(bodyPart.getBodyPartBytes());           return STATE.CONTINUE;      }        @Override      public String onCompleted() throws Exception {           // Will be invoked once the response has been fully read or a ResponseComplete exception           // has been thrown.           // NOTE: should probably use Content-Encoding from headers           return bytes.toString("UTF-8");      }        @Override      public void onThrowable(Throwable t) {      }  });    String bodyResponse = f.get();

项目主页:http://www.open-open.com/lib/view/home/1409812473728

 本文由用户 jopen 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
 转载本站原创文章,请注明出处,并保留原始链接、图片水印。
 本站是一个以用户分享为主的开源技术平台,欢迎各类分享!
 本文地址:https://www.open-open.com/lib/view/open1409812473728.html
网络工具包 Async Http Client