×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    2

    Httpconnection error

    Hi,

    I have a Problem using a HttpConnection in my program. My code looks like
    the following:

    **********************************************
    String url = "http://www.homelinux.org/Beta/servlet";
    //byte[] buf = new byte[512];

    try {
    //while(con == null){
    con = (HttpConnection) Connector.open(url);
    con.setRequestMethod(HttpConnection.GET);
    con.setRequestProperty("Accept-Language", "en-US");

    byte data[] = null;

    //Init inputstream
    int length = (int) con.getLength();
    is = con.openDataInputStream();

    ByteArrayOutputStream bStrm = new ByteArrayOutputStream();

    int ch;
    while ( (ch = is.read()) != -1) {
    bStrm.write(ch);
    }
    data = bStrm.toByteArray();

    InfoScreen infoScreen = new InfoScreen("Information", frame,
    this,
    new String(data));
    frame.display.setCurrent(infoScreen);

    }
    catch (Exception e) {
    InfoScreen infoScreen = new InfoScreen("Information", frame,
    this,
    e.getMessage());
    frame.display.setCurrent(infoScreen);

    }
    finally {

    if (is != null) {
    try {
    is.close();
    }
    catch (IOException ex1) {
    }
    }
    if (con != null) {
    try {
    con.close();
    }
    catch (IOException ex2) {
    }
    }

    }
    **************************************************

    It doesn't work properly on my Rogers' phone. Actually the weird thing is that it does get some data from server. But every time after it read certain bytes( let's say 512 bytes. It's different everytime), it would stop reading.
    What's wrong? Any suggestions anyone has would be greatly appreciated. I've nearly run out of ideas on how to address this problem.

    Thanks
    James

  2. #2
    Regular Contributor
    Join Date
    Mar 2006
    Posts
    61

    Re: Httpconnection error

    Hi,
    Try to using socket connection instead of Httpconnection..
    BR
    Ali

  3. #3
    Registered User
    Join Date
    May 2006
    Posts
    2

    Re: Httpconnection error

    Thx for your reply. But I want to know whether this is my program's problem or it's just the J2ME Httpconnection's limitation. Does anybody else encount similar problem? What's the solution?

    Thanks
    James

Similar Threads

  1. problem with Code Warrior 5.2
    By mayankkedia in forum Symbian
    Replies: 4
    Last Post: 2006-06-22, 08:26
  2. help !! about SIP errors
    By wgarnett in forum Symbian
    Replies: 3
    Last Post: 2006-05-17, 05:30
  3. S80 Platform SDK and Visual Studio .NET Linking Error
    By jayantjain in forum Mobile Java Tools & SDKs
    Replies: 1
    Last Post: 2005-10-07, 22:14
  4. problem with codewarrior 5.2
    By mayankkedia in forum Symbian Tools & SDKs
    Replies: 3
    Last Post: 2004-09-27, 16:08
  5. Cannot compile SDK's examples for 7650 platform...
    By midletsoft in forum Symbian Tools & SDKs
    Replies: 2
    Last Post: 2003-08-12, 19:11

Posting Permissions

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