设置setChunkedStreamingMode在HttpURLConnection类未能提供数据到服务器服务器、数据、setChunkedStreamingMode、HttpURLConnecti

2023-09-06 03:15:25 作者:祭恋

我的服务器版本是在我的开发机器如下:

My server version is as follows on my dev machine:

的Apache / 2.2.21(Win32的)mod_fcgid / 2.3.6

Apache/2.2.21 (Win32) mod_fcgid/2.3.6

我一直在测试的HttpURLConnection 我的项目需要很容易流capabilties。我对如何使用类读取一个伟大的故事大纲,从@BalusC。

I have been testing HttpURLConnection as my project requires easy streaming capabilties. I have read a great synopsis from @BalusC on how to use the class.

如何使用java.net.URLConnection中的火灾和处理HTTP请求?

我目前遇到的问题是当设置 setChunkedStreamingMode 。不管是什么我将它设置为我流似乎并没有使它的服务器数据流是空的,当被称为/使我的服务器API方法/连接。不过,如果我删除它,它工作正常。

The trouble I am currently having is when setting setChunkedStreamingMode. Regardless of what I set it to my stream doesn't seem to make it to the server the data stream is empty when my server api method/connection is called/made. However, if I remove it, it works fine.

我看到其他人有类似的问题:

I have seen another person with a similar issue:

的Java / Android的HttpURLConnection的setChunkedStreamingMode不工作的所有PHP服务器

但没有真正的解决方案。我无法将其设置为 setFixedLengthStreamingMode 只是因为它的内容(JSON)是可变长度。

But with no real resolution. I am unable to set it to setFixedLengthStreamingMode simply because the content (json) is variable in length.

这也不行。我可能会transfering非常大量的数据,因此不能有存储在存储器中的数据。

This is NOT OK. I potentially will be transfering very large quantities of data and hence cannot have the data stored in memory.

我的问题是,我怎么能得到setChunkedStreamingMode发挥好?它是一个服务器设置问题,或者可以将其固定在code?

My question is, how can I get setChunkedStreamingMode to play nice? Is it a server setup issue or can it be fixed in code?

修改 我现在已经测试了我的code我的生产服务器上,它的工作原理没有问题。不过,我还是想知道为什么我的本地机器我的Apache服务器出现故障。任何帮助还是多AP preciated。

EDIT I have now tested my code on my production server and it works no problem. I would however still like to know why my Apache server on my local machine fails. Any help is still much appreciated.

推荐答案

尝试添加这样的HTTP标头:

Try adding this HTTP header:

urlConnection.setRequestHeader("Transfer-Encoding","chunked");

我haved这样的问题:虽然我haved设置分块的HTTP流模式(urlConnection.setChunkedStreamingMode(0)),它不是工作,而是把HTTP头以上能正常工作

I haved a problem like this: although I haved set the chunked HTTP streaming mode (urlConnection.setChunkedStreamingMode(0) ), it not worked, but putting the HTTP header above it works fine.