【问题标题】:Set content length header in java play framework http request在java play框架http请求中设置内容长度标头
【发布时间】:2016-07-29 14:14:56
【问题描述】:

我正在使用play 2.5.x ws library 用于将文件上传到内部服务器。 我有使用 apache http/curl/postman 的示例代码。 但是当我尝试使用 ws 库时,它是如何失败的。 我无权访问内部服务器,并且它没有返回任何错误消息

我已经检查了两个请求(apache http/play WS)的请求标头,我看到“内容长度”标头 WS 请求中缺少。 我试图用

设置它
ws.url(url).setHeader().post(Source.from(Arrays.asList(fp,name)

但我得到了

"Stream has already been consumed and cannot be reset"

有什么方法可以设置内容长度吗? 或者还有什么我想念的。

【问题讨论】:

    标签: playframework multipartform-data content-length playframework-webservice


    【解决方案1】:

    不幸的是,这没有正确记录,但您可以look at the code 了解post(Source) 的工作原理:

    // If the body has a streaming interface it should be up to the user to provide a manual Content-Length
    // else every content would be Transfer-Encoding: chunked
    // If the Content-Length is -1 Async-Http-Client sets a Transfer-Encoding: chunked
    // If the Content-Length is great than -1 Async-Http-Client will use the correct Content-Length
    

    -1 是默认值。

    因此,目前,您可以设置Content-Length 或让您的服务器接受分块传输。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-13
      • 2014-12-07
      • 1970-01-01
      • 1970-01-01
      • 2014-08-07
      • 1970-01-01
      相关资源
      最近更新 更多