java自己实现的httpserver
来源:互联网 发布:sql 相同id 合并字段 编辑:程序博客网 时间:2024/06/05 14:28
package my.httpserver;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.BindException;
import java.net.ServerSocket;
import java.net.Socket;
public class Server2 {
private ServerSocket server;
public static void main(String[] args) {
new Server2().start();
}
public void start() {
try {
server = new ServerSocket(8888);
receive();
} catch (BindException e) {
System.out.println("端口已被占用");
} catch(IOException e) {
e.printStackTrace();
}
}
public void receive() {
try {
Socket client = server.accept();
byte[] data = new byte[20480];
int len = client.getInputStream().read(data);
String msg = new String(data, 0, len);
System.out.println(msg);
} catch(IOException e) {
e.printStackTrace();
}
}
}
注意post方法的数据在后面
<html>
<head><title>你好</title></head>
<body>
<form method = "get" action = "http://localhost:8888/">
用户名:<input type = "text" name = "username" id = "username">
<br>密码:<input type = "password" name = "pwd" id = "pwd">
<br><input type = "submit" value = "登录">
</form>
</body>
</html>
GET /?username=2123&pwd=nihao HTTP/1.1
Host: localhost:8888
Connection: keep-alive
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding: gzip, deflate, sdch, br
Accept-Language: zh-CN,zh;q=0.8
POST / HTTP/1.1
Host: localhost:8888
Connection: keep-alive
Content-Length: 31
Cache-Control: max-age=0
Origin: null
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36
Content-Type: application/x-www-form-urlencoded
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding: gzip, deflate, br
Accept-Language: zh-CN,zh;q=0.8
username=dazzling&pwd=haojunjie
- java自己实现的httpserver
- 树莓派实现自己的Qt HTTPserver
- Java HttpServer实现交互
- python3实现的多线程httpserver
- HttpServer的简单实现_Java
- android端HttpServer的实现
- Java HttpServer
- java httpserver
- 简单剖析一下 HttpServer的实现方式
- 使用nio实现简单的httpServer
- 利用Httplistener实现的HttpServer类
- socket实现一个简单的httpserver
- Nancy HttpServer---自己开发HttpServer (不断更新中)
- 如何开发自己的HttpServer-NanoHttpd源码解读
- 如何开发自己的HttpServer-NanoHttpd源码解读
- 简易http服务器的实现(实现)httpserver.c
- netty 简单httpserver实现
- 用libevent实现httpserver
- 创建Maven出错
- idea
- 数字图像处理matlab版第五章
- Microsoft Visual Studio 2013
- Mysql| Mysql常用函数汇总
- java自己实现的httpserver
- 第二章问题回答
- 例子:面对对象
- 网狐荣耀版手机端生成时出现MakeMD5List.exe 应用程序错误的解决办法
- awk实现文件反序输出
- C++引用
- 操作系统-最佳适应算法
- 菜鸟学习数据结构算法之路之快速排序
- ValueError: Only call `softmax_cross_entropy_with_logits` with named arguments (labels=..., logits=.