我正在实现小型Java应用程序。这个应用程序获得一些数据,从第三帕蒂资源,并需要认证之前。我首先调用get cookie(这很容易),第二次调用这个cookie来获取数据。我在googled上搜索了一下如何做到这一点,并找到了下一个解决方案-- 用J2ME处理cookie。
为了我的目的,我已经将此代码更改为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?我怎么才能破解这个?
发布于 2013-07-30 22:03:51
愚蠢的我。我没有考虑下一段代码:hpc.setRequestProperty("Accept-Encoding", "gzip, deflate");,我在ZIP响应中得到编码,所有我需要的代码都会对它进行解码。
https://stackoverflow.com/questions/17912556
复制相似问题