我正在尝试编写一个 servlet,它将通过 POST 将 XML 文件(xml 格式的字符串)发送到另一个 servlet。(非必要的 xml 生成代码替换为“Hello there”)
StringBuilder sb= new StringBuilder();
sb.append("Hello there");
URL url = new URL("theservlet's URL");
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Length", "" + sb.length());
OutputStreamWriter outputWriter = new OutputStreamWriter(connection.getOutputStream());
outputWriter.write(sb.toString());
outputWriter.flush();
outputWriter.close();
这会导致服务器错误,并且永远不会调用第二个 servlet。