Java如何使用流式编程的方式访问url呢?
下文笔者讲述HttpClient中使用流式编程的方式访问url的方法分享,如下所示:
流式编程httpGet访问url
实现思路:
1.引入httpclient5-fluent-5.13.jar,httpcore5-***.jar
2.使用其中的Request类即可实现流式编程的效果
例:流式编程httpGet访问url
package com.java265.other.httpClient;
import org.apache.hc.client5.http.fluent.Request;
import org.apache.hc.client5.http.fluent.Response;
public class HttpClient01 {
/*
* java265.com HttpClient 流式示例
*/
public static void main(String[] args) throws Exception {
Response response = Request.get("http://www.java265.com").execute();
byte[] bytes = response.returnContent().asBytes();
// 注意字符编码
System.out.println("返回信息:" + new String(bytes).toString());
}
}
版权声明
本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。


