1

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?

4

1 回答 1

0

愚蠢的我。我没有考虑下一个代码:hpc.setRequestProperty("Accept-Encoding", "gzip, deflate");我在 ZIP 响应中编码,我需要它解码的所有内容。

于 2013-07-30T22:03:51.090 回答