首页 > 其他分享 >HTTP 轻量级请求库-----Unirest

HTTP 轻量级请求库-----Unirest

时间:2022-10-27 08:33:18浏览次数:93  
标签:HTTP Unirest ----- org post 轻量级 httpclient

Unirest 是一个轻量级的 HTTP 请求库,可发起 GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS 请求。支持 Node、Ruby、Java、PHP、Python、Objective-C、.NET 等多种语言。底层是基于httpclient,所以使用Unirest之前先要引入httpclient相关的依赖。

Maven项目可以直接在pom.xml文件中引入Unirest 的依赖

       <dependency>
            <groupId>com.mashape.unirest</groupId>
            <artifactId>unirest-java</artifactId>
            <version>1.4.9</version>
        </dependency>

  底层是基于httpclient的,所以需要引入httpclient相关依赖

<dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpclient</artifactId>
    <version>4.3.6</version>
</dependency>

<dependency>
      <groupId>org.apache.httpcomponents</groupId>
      <artifactId>httpasyncclient</artifactId>
      <version>4.0.2</version>
</dependency>

<dependency>
     <groupId>org.apache.httpcomponents</groupId>
     <artifactId>httpmime</artifactId>
     <version>4.3.6</version>
</dependency>

<dependency>
      <groupId>org.json</groupId>
      <artifactId>json</artifactId>
      <version>20140107</version>
</dependency>

  测试相关依赖

       <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.13.1</version>
        </dependency>

  创建Post连接格式:

HttpResponse<JsonNode> jsonResponse = [Unirest.post(](https://link.jianshu.com?t=http://Unirest.post()"[http://httpbin.org/post](https://link.jianshu.com?t=http://httpbin.org/post)")
.header("accept", "application/json")
.queryString("apiKey", "123")
.field("parameter", "value")
.field("foo", "bar")
.asJson();

 

转自:(5条消息) HTTP 轻量级请求库-----Unirest_小菜鸟-hxh的博客-CSDN博客_unirest依赖

 

标签:HTTP,Unirest,-----,org,post,轻量级,httpclient
From: https://www.cnblogs.com/wwssgg/p/16830804.html

相关文章