客户端:
public List<String> post(List<String> toWrite){
String result = "";
List<String> allResults = new ArrayList<String>();
try {
openConnection();
connection.setDoOutput(true);
connection.setRequestMethod("POST");
initializeOutputStream();
for(int i = 0; i < toWrite.size(); i++){
out.write(toWrite.get(i));
out.newLine();
}
System.out.println(connection.getResponseCode());
System.out.println(connection.getResponseMessage());
initializeInputStream();
while((result = in.readLine()) != null){
allResults.add(result);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
closeConnection();
}
return allResults;
}
One of the attempts at the host:
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
// TODO Auto-generated method stub
List<String> incoming = …Run Code Online (Sandbox Code Playgroud)