我正在实施小型Java ME应用程序。这个应用程序从第三个patty资源获取一些数据,需要之前进行身份验证。我首先要求获取cookie(这很容易),第二次使用此cookie来获取数据。我用谷歌搜索了一下如何做,并找到了下一个解决方案 - Deal with cookie with J2ME
为了我的目的,我已将此代码更改为next:
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) {}
}
}
我得到的东西就像下一个
??ÑÁ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?
我该如何解码?
答案 0 :(得分:0)
愚蠢的我。我没有考虑下一个代码:hpc.setRequestProperty("Accept-Encoding", "gzip, deflate");
我在ZIP响应中编码,我需要它解码它。