快速开始
安装
确保当前的Java
版本为JDK[8,22]
。引入依赖:
xml
<dependency>
<groupId>cn.vlts</groupId>
<artifactId>solpic-core</artifactId>
<version>0.0.3</version>
</dependency>
properties
implementation 'cn.vlts:solpic-core:0.0.3'
TIP
Solpic
的最新版本可以通过Maven
中央仓库查询:https://central.sonatype.com/artifact/cn.vlts/solpic
开始使用
java
public static void main(String[] args) throws Exception {
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://httpbin.org/get"))
.method(HttpMethod.GET)
.build();
HttpClient httpClient = Solpic.newHttpClient();
HttpResponse<String> response = httpClient.send(request, PayloadSubscribers.X.ofString());
int statusCode = response.getStatusCode().value();
String responseBody = response.getPayload();
System.out.println(statusCode);
System.out.println("=====");
System.out.println(responseBody);
}
某次调用输出结果示例:
shell
200
=====
{
"args": {},
"headers": {
"Host": "httpbin.org",
"User-Agent": "Java-http-client/22",
"X-Amzn-Trace-Id": "Root=1-66cfd5c8-733174533bffee71226f072f"
},
"origin": "183.6.24.203",
"url": "https://httpbin.org/get"
}