代码拉取完成,页面将自动刷新
smart-http 是一款可编程的 Http 应用微内核,方便用户根据自身需求进行 Server 或 Client 的应用开发。
感兴趣的朋友请记得 Star一下该项目,并且非常欢迎有能力的朋友贡献你的想法和代码。
<dependency>
<groupId>org.smartboot.http</groupId>
<artifactId>smart-http-server</artifactId>
<version>1.1.22</version>
</dependency>
public class SimpleSmartHttp {
public static void main(String[] args) {
HttpBootstrap bootstrap = new HttpBootstrap();
// 普通http请求
bootstrap.pipeline().next(new HttpServerHandle() {
@Override
public void doHandle(HttpRequest request, HttpResponse response) throws IOException {
response.write("hello world<br/>".getBytes());
}
});
// websocket请求
bootstrap.wsPipeline().next(new WebSocketDefaultHandle() {
@Override
public void handleTextMessage(WebSocketRequest request, WebSocketResponse response, String data) {
response.sendTextMessage("Hello World");
}
});
bootstrap.setPort(8080).start();
}
}
http://localhost:8080/
,亦或采用websocket请求ws://127.0.0.1:8080/
<dependency>
<groupId>org.smartboot.http</groupId>
<artifactId>smart-http-client</artifactId>
<version>1.1.22</version>
</dependency>
public class HttpGetDemo {
public static void main(String[] args) {
HttpClient httpClient = new HttpClient("www.baidu.com", 80);
httpClient.get("/").header().keepalive(false).done()
.onSuccess(response -> System.out.println(response.body()))
.onFailure(Throwable::printStackTrace)
.done();
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。