Java/Android HttpURLConnection setChunkedStreamingMode not working with all PHP servers

前端 未结 1 1751
陌清茗
陌清茗 2021-01-05 02:44

I\'ve spent the last day or so trying to debug this issue and I\'m out of ideas. Basically I have an Android app that is POSTing some data to a PHP/Apache web server. This

相关标签:
1条回答
  • 2021-01-05 03:46

    Unfortunately I wasn't able to find a direct solution to this problem, but I was able to find a workaround. Instead of using conn.setChunkedStreamingMode I used conn.setFixedLengthStreamingMode, which I had tried before with no success. The key to getting conn.setFixedLengthStreamingMode to work is to pass it the full length of the data you are attempting to send (in this case the file), plus the length of the headers. Fortunately header length is usually fixed in code such as this, so once you figure out how big your header is (keeping in mind things like the filename, which gets sent in the header under Content-Disposition is also variable) you can just put it in as a fixed number. To figure out my header length, I ran the code first without specifying any length for the header. The error message I received back gave me an expected and an actual value for the number of bytes sent, which allowed me to calculate the header length.

    0 讨论(0)
提交回复
热议问题