×

Discussion Board

Results 1 to 10 of 10
  1. #1
    Registered User
    Join Date
    Jun 2013
    Posts
    11

    Decoded response in Java ME (Nokia Asha)

    I am implementing small Java ME app. This app gets some data from 3rd patty resource and needs to be authenticated before. I do first call for get cookies (it was easy), and the second call with this cookies for get data. I googled a little how to do it, and found next solution - Deal with cookie with J2ME

    I have changed this code to next for my purpose:

    public void getData(String url,String cookie) {
    HttpConnection hpc = null;
    InputStream is = null;

    try {
    hpc = (HttpConnection) Connector.open(url);
    hpc.setRequestProperty("cookie", cookie);
    hpc.setRequestProperty("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
    hpc.setRequestProperty("Accept-Encoding", "gzip, deflate");
    hpc.setRequestProperty("Accept-Language", "en-US,en;q=0.5");
    is = hpc.openInputStream();
    int length = (int) hpc.getLength();
    byte[] response = new byte[length];
    is.read(response);
    String strResponse = new String(response);
    } catch (Exception e) {
    System.out.println(e.getMessage() + " " + e.toString());
    } finally {
    try {
    if (is != null)
    is.close();
    if (hpc != null)
    hpc.close();
    } catch (Exception e) {}
    }
    }

    I get something like to the next

    ??ÑÁNÃ0à;O±(²§M}A-?@
    .?PYS¨Ôe¥Í@\üìde??XÊo}Vâ]hk?­6ëµóA|µvÞz'Íà?wAúêmw4í0?ÐÆ?ÚMW=?òêz CÛUa:6Ö7¼T?<oF?nh6[_0?l4?äê&)?çó³?ÅÕúf¨ä(.? ªDÙ??§?ÊP+??(:?Á,Si¾ïA¥ã-jJÅÄ8ÊbBçL)gs.S.þG5ÌÀÆéX}CÁíÑ-þ?BDK`²?\¶?ó3I÷ô±e]°6¬c?q?Ó?¼?Y.¯??Y?%?ÏP1è?ìw;?È Ò??e
    |ôh0?

    How can I decode this?

  2. #2
    Nokia Developer Champion
    Join Date
    Feb 2008
    Location
    Ahmedabad, Gujarat, India
    Posts
    3,852

    Re: Decoded response in Java ME (Nokia Asha)

    before decoding we need to what is the format in which its encoded ??

  3. #3
    Registered User
    Join Date
    Jun 2013
    Posts
    11

    Re: Decoded response in Java ME (Nokia Asha)

    I get this from the 3rd party server. I no idea what they use. When I post url via browser - it gets correct response.

    PS strResponse is "??ÑÁNÃ0à;O±(²§M}A-?@
    .?PYS¨Ôe¥Í@\üìde??XÊo}Vâ]hk?­6ëµóA|µvÞz'Íà?wAúêmw4í0?ÐÆ?ÚMW=?òêz CÛUa:6Ö7¼T?<oF?nh6[_0?l4?äê&)?çó³?ÅÕúf¨ä(.? ªDÙ??§?ÊP+??(:?Á,Si¾ïA¥ã-jJÅÄ8ÊbBçL)gs.S.þG5ÌÀÆéX}CÁíÑ-þ?BDK`²?\¶?ó3I÷ô±e]°6¬c?q?Ó?¼?Y.¯??Y?%?ÏP1è?ìw;?È Ò??e
    |ôh0?"

  4. #4
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,696

    Re: Decoded response in Java ME (Nokia Asha)

    As discussed in your other thread this data may be deflated or gzip-ed.
    Try uncompressing it, you can try this library for example: http://www.java4ever.com/index.php?s...enu=main&lang=

  5. #5
    Nokia Developer Champion
    Join Date
    Mar 2013
    Posts
    686

    Re: Decoded response in Java ME (Nokia Asha)

    You are getting a compressed (GZip) data because you told the server that you know how to deal with it (this line hpc.setRequestProperty("Accept-Encoding", "gzip, deflate")
    if you remove this data then the server will send you Uncompressed data (as long as he supports both methods) and you wont have to decompress it.
    if the server ONLY knows how to send data compressed in gzip (which i would find it very hard to believe) then you have to decompress it yourself with a gzip inflator.

  6. #6
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,696

    Re: Decoded response in Java ME (Nokia Asha)

    Shai, the other thread is here: http://developer.nokia.com/Community...E-(Nokia-Asha), that is where the gzip, deflate comes from.

  7. #7
    Registered User
    Join Date
    Jun 2013
    Posts
    11

    Re: Decoded response in Java ME (Nokia Asha)

    Thanks it helps.

  8. #8
    Registered User
    Join Date
    Jun 2013
    Posts
    11

    Re: Decoded response in Java ME (Nokia Asha)

    Hm, it works for byte[360] array but crashed on byte[2220] array..
    Should me set some additional property to "?extend" it?

  9. #9
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,087

    Re: Decoded response in Java ME (Nokia Asha)

    Quote Originally Posted by Hospodar View Post
    Hm, it works for byte[360] array but crashed on byte[2220] array..
    Should me set some additional property to "?extend" it?
    Crash may be due to heap memory issue... use smaller size array - say [512], [1024].. and see till which it works.
    thanks,
    ~Amitabh
    (Champion of the Month -Aug'13)
    Follow me on my blog for Innovative Mobile Apps

  10. #10
    Nokia Developer Champion
    Join Date
    Feb 2008
    Location
    Ahmedabad, Gujarat, India
    Posts
    3,852

    Re: Decoded response in Java ME (Nokia Asha)

    Quote Originally Posted by Hospodar View Post
    Hm, it works for byte[360] array but crashed on byte[2220] array..
    Should me set some additional property to "?extend" it?
    Yes and observe the sdk diagnostic tool at which point you are exceeding the heap size !!

Similar Threads

  1. Replies: 6
    Last Post: 2013-12-01, 16:48
  2. Cookies in Java ME (Nokia Asha)
    By Hospodar in forum Mobile Java General
    Replies: 4
    Last Post: 2013-07-30, 11:34

Posting Permissions

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