http-client

基于okhttp3封装的http工具包

License

License

Categories

Categories

CLI User Interface
GroupId

GroupId

cn.aghost
ArtifactId

ArtifactId

http-client
Last Version

Last Version

1.0.6
Release Date

Release Date

Type

Type

jar
Description

Description

http-client
基于okhttp3封装的http工具包
Project URL

Project URL

https://github.com/ggg17226/http-client
Source Code Management

Source Code Management

https://github.com/ggg17226/http-client

Download http-client

How to add to project

<!-- https://jarcasting.com/artifacts/cn.aghost/http-client/ -->
<dependency>
    <groupId>cn.aghost</groupId>
    <artifactId>http-client</artifactId>
    <version>1.0.6</version>
</dependency>
// https://jarcasting.com/artifacts/cn.aghost/http-client/
implementation 'cn.aghost:http-client:1.0.6'
// https://jarcasting.com/artifacts/cn.aghost/http-client/
implementation ("cn.aghost:http-client:1.0.6")
'cn.aghost:http-client:jar:1.0.6'
<dependency org="cn.aghost" name="http-client" rev="1.0.6">
  <artifact name="http-client" type="jar" />
</dependency>
@Grapes(
@Grab(group='cn.aghost', module='http-client', version='1.0.6')
)
libraryDependencies += "cn.aghost" % "http-client" % "1.0.6"
[cn.aghost/http-client "1.0.6"]

Dependencies

compile (8)

Group / Artifact Type Version
org.realityforge.org.jetbrains.annotations : org.jetbrains.annotations jar 1.6.0
org.reflections : reflections jar 0.9.12
com.google.guava : guava jar 30.0-jre
org.apache.commons : commons-lang3 jar 3.11
commons-codec : commons-codec jar 1.15
com.squareup.okhttp3 : okhttp jar 3.14.9
org.slf4j : slf4j-api jar 1.7.30
com.alibaba : fastjson jar 1.2.75

provided (1)

Group / Artifact Type Version
org.projectlombok : lombok jar 1.18.16

test (3)

Group / Artifact Type Version
org.junit.jupiter : junit-jupiter-api jar 5.7.0
org.junit.jupiter : junit-jupiter-engine jar 5.7.0
org.slf4j : slf4j-simple jar 1.7.30

Project Modules

There are no modules declared in this project.

http-client

使用说明

引入maven依赖

<dependency>
    <groupId>cn.aghost</groupId>
    <artifactId>http-client</artifactId>
    <version>1.0.6</version>
</dependency>

使用示例(High Level)

    @Data
    @HttpCodec
    public class TestObject {
      private String addr;
    }


    TestObject testObject =
        Get.doGet("https://file.aghost.cn/mmmmyipaddr.php?id=1", "tag", TestObject.class);

    TestObject testObject =
        Post.doPost(
            "https://file.aghost.cn/mmmmyipaddr.php?id=1",
            "tag",
            new TestObject(),
            TestObject.class);

    TestObject testObject =
        Put.doPut(
            "https://file.aghost.cn/mmmmyipaddr.php?id=1",
            "tag",
            new TestObject(),
            TestObject.class);

    TestObject testObject =
        Delete.doDelete(
            "https://file.aghost.cn/mmmmyipaddr.php?id=1",
            "tag",
            new TestObject(),
            TestObject.class);

使用示例(Low Level)

    //get请求
    HttpResponse httpResponse = Get.doGet("https://file.aghost.cn/mmmmyipaddr.php");
    log.info(JSON.toJSONString(httpResponse));

    Get.doGetAsync(
        "https://file.aghost.cn/mmmmyipaddr.php",
        new HttpCallback() {
          @Override
          public void onFailure(@NotNull Call call, @NotNull IOException e) {
            log.error(ExceptionUtils.getStackTrace(e));
            assert e == null;
          }

          @Override
          public void onSuccess(@NotNull Call call, @NotNull HttpResponse response) {
            log.info(JSON.toJSONString(response));
            assert httpResponse.getContentType().equals("application/json");
          }
        });

    //post请求
    HttpResponse httpResponse = Post.doPost("https://file.aghost.cn/mmmmyipaddr.php", null, null);

    Post.doPostAsync(
        "https://file.aghost.cn/mmmmyipaddr.php",
        null,
        null,
        new HttpCallback() {
          @Override
          public void onFailure(@NotNull Call call, @NotNull IOException e) {
            log.error(ExceptionUtils.getStackTrace(e));
            assert e == null;
          }

          @Override
          public void onSuccess(@NotNull Call call, @NotNull HttpResponse response) {
            log.info(JSON.toJSONString(response));
            assert httpResponse.getContentType().equals("application/json");
          }
        });


    //put请求
    HttpResponse httpResponse = Put.doPut("https://file.aghost.cn/mmmmyipaddr.php", null, null);

    Put.doPutAsync(
        "https://file.aghost.cn/mmmmyipaddr.php",
        null,
        null,
        new HttpCallback() {
          @Override
          public void onFailure(@NotNull Call call, @NotNull IOException e) {
            log.error(ExceptionUtils.getStackTrace(e));
            assert e == null;
          }

          @Override
          public void onSuccess(@NotNull Call call, @NotNull HttpResponse response) {
            log.info(JSON.toJSONString(response));
            assert httpResponse.getContentType().equals("application/json");
          }
        });


    //delete请求
    HttpResponse httpResponse =
        Delete.doDelete("https://file.aghost.cn/mmmmyipaddr.php", null, null);

    Delete.doDeleteAsync(
        "https://file.aghost.cn/mmmmyipaddr.php",
        null,
        null,
        new HttpCallback() {
          @Override
          public void onFailure(@NotNull Call call, @NotNull IOException e) {
            log.error(ExceptionUtils.getStackTrace(e));
            assert e == null;
          }

          @Override
          public void onSuccess(@NotNull Call call, @NotNull HttpResponse response) {
            log.info(JSON.toJSONString(response));
            assert httpResponse.getContentType().equals("application/json");
          }
        });

Versions

Version
1.0.6
1.0.5
1.0.4
1.0.3
1.0.2
1.0.1
1.0