对应网址

对应网址

http://10.173.17.104:8080/Server

User:

http://10.173.17.104:8080/Server/getUsers

1 成功

2 失败

http://10.173.17.104:8080/Server/newUsers

返回:

1 成功

2 用户名已经存在

http://10.173.17.104:8080/Server/userLogin

返回:

1 登陆成功

2 密码错误

3 用户名不存在


Goods:

http://10.173.17.104:8080/Server/getGoods

http://10.173.17.104:8080/Server/newGoods

http://10.173.17.104:8080/Server/updateGoods

http://10.173.17.104:8080/Server/deleteGoods


Activities:

http://10.173.17.104:8080/Server/getActivities

http://10.173.17.104:8080/Server/newActivities

http://10.173.17.104:8080/Server/updateActivities

http://10.173.17.104:8080/Server/deleteActivities


UploadPic

http://10.173.17.104:8080/Server/getPic

http://10.173.17.104:8080/Server/uploadPic


app发出请求代码


import java.io.DataOutputStream;
import java.io.ObjectInputStream;
import java.net.HttpURLConnection;
import java.net.URL;

public class sendToServer {
    
    String url_string = "";
    public void send(String json){
        URL url = null;
        HttpURLConnection connection = null;
        try {
            
            url = new URL(url_string);
            connection = (HttpURLConnection) url
                    .openConnection();
            connection.setDoInput(true);
            connection.setDoOutput(true);
            connection.setConnectTimeout(10000);
            connection.setReadTimeout(10000);
            connection.setRequestMethod("POST");// 设置为post方法
            
            // 输出流
            DataOutputStream outobj = new DataOutputStream(
                    connection.getOutputStream());
            
            Gson gson = new Gson();
            User user = new User();
            user.setId("aa");
            user.setClassmark("classmark");
            user.setEmail("aaa");
            user.setPassword("aaa");
            user.setPhone("111");
            String userson = gson.toJson(user);
            
            // 先写入标志服 在写 json 那么读的时候 先读取json 再读取标志
            outobj.writeInt(3);
            outobj.writeUTF(userson);

            outobj.flush();
            
            outobj.close();
            
            
            // 输入流 服务器传回来的东西
            ObjectInputStream ois = new ObjectInputStream(
                    connection.getInputStream());
            String result = (String) ois.readObject();
            ois.close();
            connection.disconnect();
            
        }catch(Exception e){
            
        }
    }

}


服务器发出反馈的代码

//反过来的代码 

            DataInputStream ios = null;
            ios = new DataInputStream(request.getInputStream());
            ObjectOutputStream oos = null;
            oos = new ObjectOutputStream(response.getOutputStream());       
            //读取标志符
            int i = ios.readInt();
            
            System.out.println(i);
            
            User user = new User();
            user.setId("hahaha");
            user.setPassword("1234");
            //user.setIdentity("1111");
            
            Gson gson = new Gson();
            String string = gson.toJson(user);
            
                
            //回传对象
            oos.writeObject(string);
            


推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 131,827评论 18 138
  • 一、概念(载录于:http://www.cnblogs.com/EricaMIN1987_IT/p/3837436...
    yuantao123434阅读 7,812评论 6 151
  • 1. Java基础部分 基础部分的顺序:基本语法,类相关的语法,内部类的语法,继承相关的语法,异常的语法,线程的语...
    子非鱼_t_阅读 30,639评论 18 399
  • 你怕表达不出 最想传达的心意 所以你 买了商店里最好看的信纸 练了一手漂亮的字 精心挑选明信片 拍下身边极致的风景...
    卷施阅读 75评论 0 2
  • 认识精力变化状态,系统地训练,提升自我认知自我调整能力,提升自己的精力管理能力,做到高效能! 节奏 平衡 低血糖指...
    LiHongxi阅读 99评论 0 0