×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    Jul 2008
    Posts
    27

    problem in http connection content length

    Hi,
    I am using following lines of code to find out how many bytes are to be read from data input stream after i get its available length from httpConnection.

    inputStream = httpConnection.openDataInputStream();
    contentLength = (int)httpConnection.getLength();

    now in some cases, i get contentLength = -1, which is giving -ive array index Exception.

    till yet, i am unable to find out why it is giving me -1 count as I know there are contents available to be read on the server.

    any suggestion about how to solve this issue.

    Regards,
    Kashif Nawaz

  2. #2
    Nokia Developer Champion
    Join Date
    Nov 2007
    Location
    Rome, Italy
    Posts
    2,406

    Re: problem in http connection content length

    Hi Kashif,

    content length availability depends on the headers sent back from the server on client request. If server does not sent the "Content-Length" header to your MIDlet, then using getLength() method will give you that -1 result. In this case, a possible method to retrieve all the response bytes is to read them one by one until you read a -1 value.

    Hope it helps,
    Pit

  3. #3
    Registered User
    Join Date
    Jul 2008
    Posts
    27

    Re: problem in http connection content length

    thanks jappit, thats what I have done now although I don't think it is a better option as I don't want to use long loops, so looking for some other option.

    any way until I don't want other one, its probably making my application not stop.

    Regards,
    Kashif Nawaz

  4. #4
    Nokia Developer Champion
    Join Date
    Nov 2007
    Location
    Rome, Italy
    Posts
    2,406

    Re: problem in http connection content length

    If you have control over server code, you can easily add the Content-Length header to its responses, so that your MIDlet could behave like you desire.
    Otherwise, apart from reading response bytes and checking for its end, I have no further hints

    Pit

Similar Threads

  1. Problem in testing HTTP connection on emulator
    By nitinmajithia in forum Symbian Networking & Messaging (Closed)
    Replies: 2
    Last Post: 2006-09-29, 13:04
  2. HTTP Connection problem with real series 40 device
    By pagadi in forum Mobile Java Networking & Messaging & Security
    Replies: 2
    Last Post: 2004-06-17, 09:28
  3. NOKIA vs. SIEMENS HTTP connection problem?
    By imarenic in forum Mobile Java Networking & Messaging & Security
    Replies: 0
    Last Post: 2003-11-03, 09:03
  4. Replies: 2
    Last Post: 2003-02-19, 03:10

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×