日期:2014-05-18  浏览次数:20561 次

java在http请求中传递大数据
现在一个请求中,有一个参数的值比较多数据,需要向header中以流的形式写入数据,然后服务器端再通过流的形式从header中取数据,该怎么做

------解决方案--------------------
直接下载不就得了,还要往head里写那么多数据
------解决方案--------------------
引用:
Quote: 引用:

直接下载不就得了,还要往head里写那么多数据
可能是我没表述明白,现在是客户端向一个接口发送一个请求,里面有几个参数,一些参数数据小的就直接在请求中“?c参数名=参数值”的传过去,而其中有个参数的数据是比较大的,问过老大,我们老大说可以以流的形式写入header中一起发过去,服务器端在通过流的形式接收就好了,问题就在于现在不知道怎么把数据写入headr中

servlet中定义了doHead

 doHead

protected void doHead(HttpServletRequest req,
                      HttpServletResponse resp)
               throws ServletException,
                      java.io.IOException

    Receives an HTTP HEAD request from the protected service method and handles the request. The client sends a HEAD request when it wants to see only the headers of a response, such as Content-Type or Content-Length. The HTTP HEAD method counts the output bytes in the response to set the Content-Length header accurately.

    If you override this method, you can avoid computing the response body and just set the response headers directly to improve performance. Make sure that the doHead method you write is both safe and idempotent (that is, protects itself from being called multiple times for one HTTP HEAD request).

    If the HTTP HEAD request is incorrectly formatted, doHead returns an HTTP "Bad Request" message.

    Parameters:
        req - the request object that is passed to the servlet
        resp - the response object that the servlet uses to return the headers to the clien
    Throws:
        java.io.IOException - if an input or output error occurs
        ServletException - if the request for the HEAD could not b