ws-http.java 给女生使用的简单无依赖的HTTP Client库

ws-http.java

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

仓库地址: https://github.com/toohamster/ws-http.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 切记

你可能感兴趣的:(Java)