سؤال

I'm working on a project where i have to use HttpUrlConnection (Android~) for reading the input stream.

It turns out that when i'm reading the input stream the data is malformed and has a bigger size from the original content (which is sent by the server). Now, the server response header contains both "Content-Length" and "Transfer-Encoding: chunked", which from what i know is an issue as both of them shouldn't coexist.

Aside from that the input stream received from HttpUrlConnection contains all body content (with chunks offset informations).

I have two questions:

  • Shouldn't the HttpUrlConnection handle chunked data?
  • How to get the data from input stream without chunked informations?
هل كانت مفيدة؟

المحلول

The HttpUrlConnection should be handling chunked data, you're correct. The fact that you're seeing these headers at all means they're probably being malformed somewhere, and something has already sent either a \n\n or \r\n\r\n, so the HttpUrlConnection views it as part of the actual transmission.

If you WANT to be getting the raw data, use a socket and connect to the url on the correct port (probably 80, 443 for ssl)

EDIT: java.net.URLConnection states under the connect() method

Interact with the resource; query header fields and contents.

This shows that a URLConnection, prior to reading anything in from any sort of provided reader, queries the header information. Pardon me for not including this the first time.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top