protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
URL url = new URL("http://localhost:8080/testy/Out");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setRequestMethod("POST");
PrintWriter out = response.getWriter();
for(Enumeration e = request.getHeaderNames(); e.hasMoreElements();) {
Object o = e.nextElement();
String value = request.getHeader(o.toString());
out.println(o + "--is--" + value + "<br>");
connection.setRequestProperty((String) o, value);
}
connection.connect();
}
我寫上面的代碼在servlet張貼形式所以比這個servlet一些替換的位置,但它不是working.is它好使用connection.setRequestProperty設置頭文件字段與傳入servlet請求中的內容。從請求對象的請求報頭複製到URLConnection對象
沒有實際上我試圖獲取一些遠程URL與當前請求的標題。 – 2010-04-01 12:09:44
或事後其實不是..?否則將它設置爲接受似乎是錯誤的。 – BalusC 2010-04-01 22:50:28