---
title: "ws-http.java 给女生使用的简单无依赖的HTTP Client库"
author: "vb2005xu"
date: "2016-09-18T18:39:40Z"
tags: []
categories: ["开源软件"]
slug: "ws-http-java-http-client"
draft: false
lastmod: "2016-09-18T18:40:20Z"
id: 2324931
url: "https://vb2005xu.iteye.com/blog/2324931"
---

# ws-http.java

好久没有敲过java代码了,今天我家妹纸问我怎么写http post,第一想起来的就是 httpclient,找了下写个简单的东西搞个这么大的库,顺顺觉得杀鸡用牛刀了,记得以前jdk里面是自带httpclient的*sun.net.www.http.HttpClient*,jdk8里面好像移除了,没办法,整个简单的吧,够用就行.

仓库地址: [https://github.com/toohamster/ws-http.java](https://github.com/toohamster/ws-http.java)

```java
Response httpResponse = new Request("http://www.yacebao.com")
        .getResource();

String responseBody = httpResponse.getBody();

// 
Response httpResponse = new Request("http://www.yacebao.com/")
        .addHeader("x-my-header", "foobar")
        .addQueryParameter("foo", "bar")
        .getResource();

String responseBody = httpResponse.getBody();

// Posts a simple JSON object to the server
Response httpResponse = new Request("http://www.yacebao.com/")
        .addHeader("x-my-header", "foobar")
        .addQueryParameter("foo", "bar")
        .setBody("{foo: 'bar'}")
        .postResource();

String responseBody = httpResponse.getBody();
```

#### 不支持HTTPS 切记