對應(yīng)網(wǎng)址
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 用戶名已經(jīng)存在
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發(fā)出請求代碼
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");// 設(shè)置為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);
// 先寫入標(biāo)志服 在寫 json 那么讀的時候 先讀取json 再讀取標(biāo)志
outobj.writeInt(3);
outobj.writeUTF(userson);
outobj.flush();
outobj.close();
// 輸入流 服務(wù)器傳回來的東西
ObjectInputStream ois = new ObjectInputStream(
connection.getInputStream());
String result = (String) ois.readObject();
ois.close();
connection.disconnect();
}catch(Exception e){
}
}
}
服務(wù)器發(fā)出反饋的代碼
//反過來的代碼
DataInputStream ios = null;
ios = new DataInputStream(request.getInputStream());
ObjectOutputStream oos = null;
oos = new ObjectOutputStream(response.getOutputStream());
//讀取標(biāo)志符
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);