Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3998028
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T07:28:28+00:00 2026-05-20T07:28:28+00:00

I am trying to program a very simple Mobile Application (J2ME) in java. The

  • 0

I am trying to program a very simple Mobile Application (J2ME) in java. The idea is to access a website via URL input and read the contents of the website into a buffer.

Here’s the problem. This works perfectly fine for some URL’s but not others? The example below (wikipedia) works fine. But take “http://java.com/en/about/” as an example and the “HttpConnection hc” returns -1 for getLenght() so there is no content to read into the buffer?

Here’s my code:

        String url = "http://en.wikipedia.org/wiki/RSS";

        //Sets up HttpConnection and InputStream using the URL variable
        HttpConnection hc = null;
        InputStream is = null;

        try {
            hc = (HttpConnection) Connector.open(url);
            is = hc.openInputStream();
        } catch (IOException ie) {
            System.out.println(ie.getMessage());
        }

        //Reader object created to read input from InputStream
        Reader rdr = new InputStreamReader(is);

        //Variable "content" will store HTML code
        String content = "";

        //Get the lenght of the data to set the buffer sizes
        int len = (int) hc.getLength();

Any ideas? let me know if I’ve missed anything out!

Just for info I am using Netbeans 6.9.1

Library for HttpConnection is “javax.microedition.io.HttpConnection;” + “import javax.microedition.io.Connector;”

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T07:28:29+00:00Added an answer on May 20, 2026 at 7:28 am

    The HTTP response from java.com is

    HTTP/1.1 200 OK
    Server: Sun-Java-System-Web-Server/7.0
    Date: Wed, 23 Feb 2011 11:07:44 GMT
    Content-Type: text/html;charset=UTF-8
    Set-Cookie: JSESSIONID=B62F3DFB233BB2806018EC721F6C3FD7; Path=/
    Content-Encoding: gzip
    Vary: accept-encoding
    Transfer-Encoding: chunked
    

    The HTTP response from wikipedia is

    HTTP/1.0 200 OK
    Date: Wed, 23 Feb 2011 10:18:56 GMT
    Server: Apache
    Cache-Control: private, s-maxage=0, max-age=0, must-revalidate
    Content-Language: en
    Vary: Accept-Encoding,Cookie
    Last-Modified: Fri, 18 Feb 2011 00:23:59 GMT
    Content-Encoding: gzip
    Content-Length: 24905
    Content-Type: text/html; charset=UTF-8
    Age: 2984
    X-Cache: HIT from sq61.wikimedia.org, MISS from sq38.wikimedia.org
    X-Cache-Lookup: HIT from sq61.wikimedia.org:3128, MISS from sq38.wikimedia.org:80
    Connection: keep-alive
    

    As you see, the HTTP response of http://java.com/en/about/ doesn’t contain Content-Length header, the content is chunked.

    So, the getLength() return -1.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to compile a very simple program in Java 1.6 on Ubuntu Jaunty,
I'm trying out a very simple Java program that uses Scanner and its method
I am trying to create a very simple application (part of my learning program),
I'm trying to write a very simple program, I want to print out the
I'm trying to write a very simple image processing program for fun and practice.
I'm trying to use AppWeb, and i wrote a very simple program to embed
I am just trying to compile and run a very simple test program, but
I have a very simple program that I am trying to improve performance. One
i am trying to develop a very simple program for classifying and categorising documents
I'm learning smalltalk right now and am trying to make a very simple program

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.