服务器
服务器搭建在
http://172.93.46.196:8300
页面菜单点击【更新】
或者通过链接
http://172.93.46.196:8300/update
可以访问最新的10条记录的页面
WEB API
http://172.93.46.196:8300/addRecords
以Post方法向服务器提交json数据
json数据格式
{"time":"12:03","freq":14.853,"ultrasound":0.17,"energy":0.10,"power":0.946,"count":1860,"status":true}
Socket 模拟Http访问
String postParams = "{\"time\":\"12:05\",\"freq\":14.853,\"ultrasound\":0.17,\"energy\":0.10,\"power\":0.946,\"count\":1860,\"status\":true}";
//上面java双引号需要斜线转义
int paramsLen = postParams.length();
StringBuffer post = new StringBuffer(512);
post.append("POST /addRecords HTTP/1.1\r\n");
post.append("Host: 172.93.46.196\r\n");
post.append("Accept: text/html\r\n");
post.append("Connection: Close\r\n");
post.append("Content-Length: " + paramsLen + "\r\n");
post.append("Content-Type: application/json\r\n");
post.append("\r\n");
post.append(postParams);
Socket socket = new Socket("172.93.46.196", 8300);
PrintWriter outWriter = new PrintWriter(socket.getOutputStream());
outWriter.println(post);
outWriter.flush();