发送HTTP POST请求,但JBOSS收到一个空的GET请求

时间:2012-08-02 10:36:20

标签: java http jsp post jboss-4.2.x

我在jboss 4.2.2服务器上运行了一个jsp页面。在jsp我尝试使用request.getMethod()和request.getHeaderNames()等方法打印http post请求的标头。我确定该请求是一个http帖子,因为我从另一个程序生成它,但是jsp打印是一个http get 请求,打印的内容长度是-1,打印的标题不匹配标题即时发送。

生成请求的应用程序的代码或多或少是这样的:

    URL url = new URL(the_url);
    HttpURLConnection con = (HttpURLConnection) url.openConnection();
    con.setDoOutput(true);
    con.setDoInput(true);
    con.setRequestMethod("POST");
    con.setRequestProperty("Content-type", "application/timestamp-query");
    con.setRequestProperty("Content-length", String.valueOf(data.length));
    out = con.getOutputStream();
    out.write(data);
    out.flush();

我尝试打印请求标头的应用程序代码是:

    <%@page import="java.io.InputStream"%>
    <%@page import="java.util.Date"%>
    <%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"
    import="java.util.Enumeration"
    import="java.io.File"
    import="java.io.FileOutputStream"
    import="java.util.Date"%><%
    File logfile = new File("/home/tsa/logfile");
    FileOutputStream log_os = new FileOutputStream(logfile);
    Enumeration header_names = request.getHeaderNames();
    log_os.write(("cont-len: "+request.getContentLength()+"\r\n").getBytes());
    log_os.write(("method: "+request.getMethod()+"\r\n").getBytes());
    while (header_names.hasMoreElements()) {
        String name = (String)header_names.nextElement();
        log_os.write((name+": "+request.getHeader(name)+"\r\n").getBytes());
    }
    log_os.close();%>

我应该收到的HTTP数据:

    POST / HTTP/1.1
    Content-type: application/timestamp-query
    User-Agent: Java/1.7.0_05
    Host: localhost:8080
    Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
    Connection: keep-alive
    Content-Length: 51

    MDECAQEwITAJBgUrDgMCGgUABBSg8UkKINAhHJl7RLw1fhly3quK4wYGBACPZwEBAQH/

我收到的HTTP数据:

    User-Agent: Java/1.7.0_05
    Host: 192.168.56.101:8080
    Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
    Connection: keep-alive

    The method reported is GET and the Content-Length: -1

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

我有同样的问题。我更新到JDK 1.7.0_u21并且问题消失了。